JSI Tip 7321. How do I convert a Julian day to a date?

Jerold Schulman

October 13, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A Julian day is a continuous count of days from 12 noon on January 1, 4713 BC. It should not be confused with a Julian date, which numbers days in each year from 001 through 365 or 366, where Jan. 1 is 001, Feb. 28 is 059, March 1, is either 060 or 061, etc...

Using an algorithm developed by Fliegel, H. F. and van Flandern, T. C. (1968), Communications of the ACM, Vol. 11, No. 10 (October, 1968), I have scripted JD2Date.bat to convert a Julian day to a Gregorian calendar date.

The syntax for using JD2Date.bat is:

call jd2date JulianDay Year Month Day

where JulianDay contains the Julian day to be converted, Year is a call directed environment variable that will contain the 4 digit year, Month is a call directed environment variable that will contain the 2 digit month, and Day is a call directed environment variable that will contain the 2 digit day.

JD2Date.bat contains:

@echo offif {%4}=={} @echo Syntax call JD2Date JulianDay Year Month Day&goto :EOFsetlocalset /a JD=%1set /a L=%JD%+68569set /a N=4*%L%/146097set /a L=%L%-(146097*%N%+3)/4set /a I=4000*(%L%+1)/1461001set /a L=%L%-1461*%I%/4+31set /a J=80*%L%/2447set /a K=%L%-2447*%J%/80set /a L=%J%/11set /a J=%J%+2-12*%L%set /a I=100*(%N%-49)+%I%+%L%if %J% LSS 10 set J=0%J%if %K% LSS 10 set K=0%K%endlocal&set %2=%I%&set %3=%J%&set %4=%K%

NOTE See How do I convert a date to a Julian day?

NOTE: I have modified the General purpose date math routine to calculate using a Julian day.

NOTE: See How do I convert a calendar date to a Julian date?

NOTE: See How do I convert a Julian date to a calendar date?

NOTE: Oct. 14, 2003 is Julian day 2452927.



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like