-1

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

DelphiCoding
  • 23
  • 1
  • 6
  • You might have more luck when you add an offset for the current year. The Julian Date for the 14th August 2014 is something about 2456883 - 2456884. – Uwe Raabe Nov 24 '14 at 13:10

2 Answers2

4

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 
LU RD
  • 34,438
  • 5
  • 88
  • 296
  • Unfortunately I didnt understand you. can you give me an example? – DelphiCoding Nov 24 '14 at 13:48
  • I read the Julian date string which is 226 from a text file. So I can not use reverse functions.. – DelphiCoding Nov 24 '14 at 14:02
  • It sounds like your "Julian Date" really isn't one. It sounds more like your value is "the number of days into the current year, starting with January 1st". That would mean that a Julian date (in your definition) would be different, depending on whether or not your base year is a leap year or not, ie. your "Julian date" could be either August 13th (in leap years) or August 14th (in other years). Doen't sound like a very fixed definition of Julian dates. In order to use your system, you'd need to include the year, ie. Julian date 2014#226 = Aug 14, and Julian date 2012#226 is Aug 13. – HeartWare Nov 24 '14 at 14:10
  • @DelphiCoding, You have to know the year as well. It strikes me that your input is the day of year (sometimes called a julian day in certain data loggers). Then your TDateTime is EncodeDate(2014,1,1) + 226. – LU RD Nov 24 '14 at 14:11
  • Well I know the year.So what should I do? I have 226 the julian days and I have the year 2014.. What can be the function or clause in delphi to find the date? – DelphiCoding Nov 24 '14 at 14:16
  • myDT := EncodeDate(2014,1,1) + yourJulianDay; What is the 1,1 parameters mean? – DelphiCoding Nov 24 '14 at 14:19
  • January 1st. EncodeDate converts a Year,Month,Day value into a TDate (or TDateTime) value. – HeartWare Nov 24 '14 at 14:20
  • 1
    @DelphiCoding, now it is time to get a good look at the documentation. – LU RD Nov 24 '14 at 14:21
0

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)

HeartWare
  • 7,464
  • 2
  • 26
  • 30
  • I have added this function to my program. And send two parameters; I send the year 2014 and Day( which I read from text as julian days) but the result shows like some interger for ex: 41962 – DelphiCoding Nov 24 '14 at 14:24
  • @DelphiCoding, use DecodeDate to resolve this as an actual date, or DateTimeToString. – LU RD Nov 24 '14 at 14:26
  • Yes. That's because a TDate (or TDateTime) is a counter of days (and fractionaly days) since some day in the past. If you want to convert this to a displayable string, look up the FormatDateTime function. Look here: http://www.delphibasics.co.uk/RTL.asp?Name=FormatDateTime – HeartWare Nov 24 '14 at 14:27