Delphi Julian Date to Normal Date

2.8k views Asked by At

I would like to convert Julian Date value to normal date. Can anyone please help me? I have tried JulianDateToDateTime(somedouble value) but it raised exception. Then I tried ModifiedJulianDateToDateTime(some double value) it posted a date but its totaly wrong. For example my Julian Value is 226. It says that it must show 14 th August. But I couldnt convert it usig delphi. Thanks

2

There are 2 answers

3
HeartWare On BEST ANSWER

If your "Julian Date" really is "Julian Day" (ie. the number of days into a given year, a.k.a. Ordinal Date), then you can use the following function to convert it to a TDate (you specify the year the Julian Day should be considered to be in):

uses DateUtils;

FUNCTION JulianDay(Year,Day : Cardinal) : TDate;
  BEGIN
    Result:=IncDay(EncodeDate(Year,1,1),PRED(Day))
  END;

This will return August 14th for JulianDay(2014,226)

8
LU RD On

System.DateUtils.JulianDateToDateTime converts a Julian Date to a TDateTime value.

From documentation:

The Julian date is the number of days, including fractional days, since 4713 BC January 1, Greenwich noon.

And for System.DateUtils.ModifiedJulianDateToDateTime:

The modified Julian date is the number of days, including fractional days, since Greenwich midnight on November 17, 1858. Modified Julian dates are based on Julian dates, but adjusted to use midnight rather than noon as a starting point and they use a more recent date as a starting point.

So you have to enter a Julian Date based on either of those starting points.


You can use the reverse functions to get a correct Julian Date: DateTimeToJulianDate/DateTimeToModifiedJulianDate.


In comments it seems as the date you have is the day number of a certain year (sometimes referred to as the Julian Day in meteorological data logging systems).

Then use this:

myDT := EncodeDate(2014,1,1) + yourJulianDay - 1;  // If the year is 2014