## 2.2 Julian Day Number - Algorithm Forms

### 2.2.1 Gregorian Date to Julian Day number

The previous algorithm development section justifies the following general algorithm for converting a Gregorian Date into a Julian Day Number. In this description:
**[x]** = the greatest integer that does not exceed x. For example, [-1.5]=-2. This is sometimes called the floor function (for example in C/C++).
**INT(x)** = [x] NOTE: some computer languages have a different definition.

**FIX(x)** = the number x without its fraction. For example, FIX(-1.5)=-1

**x\y** = FIX(x/y)

STEP 1 Calculate the value of Z using **ONE** of the following methods:

- Z = Y + (M-14)\12

- IF M<3 THEN Z=Y-1 ELSE Z=Y

- On some computers, the month and year can be placed in memory locations so that a subtraction of the month will carry into the year when the month is January or February.

STEP 2 Calculate the value of F using **ONE** of the following methods:

- F is the value of a vector indexed by M. This vector has values 306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275. This method is usually the fastest method and often takes less computer memory to implement.

- IF M<3 THEN M=M+12

F = (153*M-457)\5

- IF M<3 THEN M=M+12

F = (979*M-2918)\32

This allows a shift to carry out the division.

- F = (979*(M-12*((M-14)\12))-2918)\32

This eliminates the need for an IF test and carries out the division using a shift.

- If real arithmetic is desired,

IF M<3 THEN M=M+12

F=FIX(30.6*M-91.4) = -122+FIX(30.6*(M+1))

can be used although real arithmetic is usually slower and takes more code space. Other coefficients are possible as described in the previous section. Note that since M is 3 or greater, 30.6*M-91.4 is always positive and either FIX or the greatest integer function can be used.

STEP 3 The Julian Day Number for a Gregorian date is

D+F+365*Z+[Z/4]-[Z/100]+[Z/400] + 1721118.5

This expression is valid for any Gregorian date, even proleptic Gregorian dates including those for negative years.

For example, the following sequence can be used to calculate the Julian Day Number from a Gregorian date:

IF M < 3 THEN

M = M + 12

Y=Y-1

END IF

JD = D + (153 * M - 457) \ 5 + 365 * Y + [Y / 4] - [Y / 100] + [Y / 400] + 1721118.5

### 2.2.2 Julian Date to Julian Day number

There are two modifications of the Gregorian date to Julian Day Number algorithm that needs to be made in order to produce a Julian date to Julian Day Number algorithm. First, the base date of March 1 of the year 0 as a Julian date is 1721117.5 so our constant is 1721116.5 rather than 1721118.5. Thus, for March 1, 0 (Julian date), our day number is 1, which, when added to our constant of 1721116.5 producing the desired JD of 1721117.5. The second modification is to count leap years every 4 years and not exclude the century years that are not divisible by 400. Thus our account of leap years is simply 365 * Y + [Y / 4] which is sometimes expressed as [365*Y+[Y/4]] = [365.25*Y]. Thus our Julian Day Number for a Julian Date is

D+F+365*Z+[Z/4] + 1721116.5

where the values of D, F, and Z are as before. For example, the following sequence can be used to calculate the Julian Day Number from a Julian Date:

IF M < 3 THEN

M = M + 12

Y=Y-1

END IF

JD = D + (153 * M - 457) \ 5 + 365 * Y + [Y / 4] + 1721116.5

AESIR RESEARCH HOME PAGE

LAST MODIFIED: March 18, 2000