Search code examples
delphidatetimejulian-date

Delphi Julian Date to Normal Date


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


Solution

  • 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)