Converting Julian Date to .NET DateTime
By Tony - Last updated: Saturday, February 18, 2006 - Save & Share - 2 Comments
Want to convert a Julian Date to a .NET DateTime? Heres an easy (C#) way to do that
////// Will Convert a 7 digit Julian Date to a .NET DateTime. /// 7 digit Julian dates are common in some legacy applications /// such as JDE World, OneWorld, EnterpriseOne. You can easily make this /// convert 8 digit julians (more common) just by removing the line that adds /// 1900000 to the input date. /// public static DateTime JulianToDateTime(int julianDate) { int RealJulian = julianDate + 1900000; int Year = Convert.ToInt32(RealJulian.ToString().Substring(0,4)); int DoY = Convert.ToInt32(RealJulian.ToString().Substring(4)); DateTime dtOut = new DateTime(Year,1,1); return dtOut.AddDays(DoY-1); }
2 Responses to “Converting Julian Date to .NET DateTime”
Comment from Tony
Time April 24, 2008 at 8:25 am
I disagree.
The documentation on this says
“Returns a DateTime equivalent to the specified OLE Automation Date”
I went ahead and tested this anyway with the value of 2008001 - which should be 2008-01-01. That method returned a DateTime for 9/18/7397
Unless you can figure out a fancy formula to get you from 2008001 to 39448 (the OLE date of 2008-01-01), I can’t see using FromOADate for converting Julian numeric dates.
Write a comment
You need to login to post comments!
Comment from zappster
Time April 23, 2008 at 6:33 am
There is an easier way. The datetime class has a method to process this. Use the following:
To get a datetime from a Julian date:
DateTime.FromOADate(julianDate);
To get a Julian date from a datetime:
DateTime.ToOADate(dateTimeValue);