JSI Tip 7105. How do I convert a calendar date to a Julian date?


Webster defines the Julian calendar as: "the calendar as regulated by Julius Caesar, giving every fourth year 366 days, the other years having 365 days each: the months were the same as in the Gregorian or New Style calendar now used."

The Julian date, not to be confused with the Julian day, a continuous count of days from 12 noon on January 1, 4713 BC, 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...

I have scripted ToJD.bat to convert a date to a Julian date. The syntax for using ToJD.bat is:

call ToJD yyyy mm dd JD3 JD

Where:

yyyy is the four digit year of the date you wish to convert.
mm   is the 1 or 2 digit month of yyyy.
dd   is the 1 or 2 digit day of mm in yyyy.
JD3  is a call directed environment variable that will contain the 3 digit Julian date.
JD   is a call directed numeric environment variable that will contain the Julian date.
ToJD.bat contains:
@echo off
if \{%5\}==\{\} @echo Syntax: Call ToJD yyyy mm dd JD3 JD&goto :EOF
setlocal
set /a year=%1
set /a mm=100%2%%100
set /a dd=100%3%%100
set /a yyyy=%1
set /a mm=100%2%%100
set /a dd=100%3%%100
set offset=000000031059090120151181212243273304334
set /a leapyear=%year%%%4
if %leapyear% EQU 0 set offset=000000031060091121152182213244274305335
set /a off=%mm% * 3
call set monoff=%%offset:~%off%,3%%
set /a monoff=1000%monoff%%%1000
set /a JD=%monoff% + %dd%
set JD3=%JD%
if %JD% LSS 10 set JD3=0%JD%
if %JD% LSS 100 set JD3=0%JD3%
endlocal&set %4=%JD3%&set %5=%JD%
NOTE: You may wish to see the following:

How do I convert a Julian date to a calendar date?

How do I convert a date to the day number and day name?

What is the ISO week number and day for a given date?

How do I convert an ISO year, week, and day to a calendar date?



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