Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet

Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Friday, March 06, 2009

Today to Julian Date value inside Dynamics AX, X++

I hope everyone is having a great Friday evening, and is ready for the weekend. In light of it being Friday, thought I would share something, maybe some of you already know.

In a project I am working on, one of the needs is to have Julian Date values for specific Date's. This is for an integration project, and the integrating software to Dynamics AX is expecting this value. There can be some possible hang ups if the 0 value date is different, but that's is not anything I can help. (Unless I create a custom Julian function that has the same Zero based starting point.)

Anyway I thought for sure there would be an X++ built in function or WinAPI call. I did not find one, so I turned to the next level in such things, .Net.

The following is code example of taking Today() method value and turning it into a Julian Date value representation:

System.DateTime CurrDT;
int64 jd;

CurrDT = new System.DateTime(Year(Today()),

jd = CurrDT.ToOADate();
info(strfmt("Today is: %1 and Julian Value is: %2",Today(),jd));

So what I do is take and create an instance of the .Net System.DateTime class. Then set it on the new / constructor call to be today's Year, Month, Day. Then I take and call the method off of that DateTime object, ToOADate(). I set this to an internal Int64 variable, and then call an info() to show the difference between the standard date value and the Julian date value.

You can learn more about the ToOADate() method call by going to it's MSDN article stub found here: DateTime.ToOADate - MSDN Home

This is from the MSDN stub for the DateTime.ToOADate method:
"An OLE Automation date is implemented as a floating-point number whose value is the number of days from midnight, 30 December 1899. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25."

So on any windows based system, you should be ok, because 99% should use the same basis for a julian date value. However you might have to work with this value or create your own custom julian date function if the zero data basis for the system your integrating with is different that the 'midnight, 30 December 1899' value that the .Net DateTime.ToOADate() method call uses.

Now, honestly, that more than I thought I would ever learn about a Julian Date value. I hope this helps someone out, and if there is another way, I am all ears, leave a comment and I will update this post to reflect such options.

Check back soon, Convergence is next week and there will be all kinds of great post from it. Also I plan on really taking the interview with Lachlan Cash and expanding on it. A lot of great things came out of that interview that need explaining and more detail. See you next time, and have a great weekend!

"Visit the Dynamics AX Community Page today!"

Labels: , , , , , ,


Post a Comment

<< Home

Copyright 2005-2011, J. Brandon George - All rights Reserved