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

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 off
if \{%4\}==\{\} @echo Syntax call JD2Date JulianDay Year Month Day&goto :EOF
setlocal
set /a JD=%1
set /a L=%JD%+68569
set /a N=4*%L%/146097
set /a L=%L%-(146097*%N%+3)/4
set /a I=4000*(%L%+1)/1461001
set /a L=%L%-1461*%I%/4+31
set /a J=80*%L%/2447
set /a K=%L%-2447*%J%/80
set /a L=%J%/11
set /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.



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish