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

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 Date2JD.bat to convert a Gregorian calendar date to a Julian day.

The syntax for using Date2JD.bat is:

call date2jd Year Month Day JulianDay

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

Date2JD.bat contains:

@echo off
if \{%4\}==\{\} @echo Syntax call Date2JD Year Month Day JulianDay&goto :EOF
setlocal
set /a I=%1
set /a J=100%2%%100
set /a K=100%3%%100
set /a JD=%K%-32075+1461*(%I%+4800+(%J%-14)/12)/4+367*(%J%-2-(%J%-14)/12*12)/12-3*((%I%+4900+(%J%-14)/12)/100)/4
endlocal&set /a %4=%JD%
NOTE See How do I convert a Julian day to a date?

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