3.2 Julian Day Number to Julian and Gregorian Date - Algorithm Forms

3.2.1 Julian Day number to Gregorian Date

The previous algorithm development section justifies the following general algorithm forms for converting a Julian Day Number into a Gregorian Date. In this description:

STEP 1 Let JD be the Julian Day Number. Calculate

    Z = INT(JD - 1721118.5)

    R = the fractional part of JD - 1721118.5 = (JD - 1721118.5) - Z

STEP 2 Calculate the value of A which is the number of full centuries:

STEP 3 Calculate the days within the whole centuries (in the Julian Calendar) by adding back days removed in the Gregorian Calendar. The value of B is this number of days minus a constant.

STEP 4 Calculate the value of Y, the year in a calendar whose years start on March 1:

STEP 5 Calculate the value of the day count in the current year using ONE of the following:

  1. C = Z + A - INT(A/4) - INT(365.25*Y)
  2. C = FIX(B - INT(365.25*Y)) + 1
    This form especially convenient in languages where the assignment of a real to an integer rounds up because B and therefore (B - INT(365.25*Y)) always have a fractional part of 0.75 or greater. In such languages,

    C = B - INT(365.25*Y)
    where C is an integer and B is a real.

STEP 6 Calculate the value of the month in the current year using ONE of the following:

  1. M = FIX((5*C + 456)/ 153)

  2. M = FIX((535*C + 48950)/ 16384)

    (Note that 16384 is 2^14 and the division can be implemented with shifts if the number has a binary representation.)

  3. M = FIX((2140*C + 195800)/ 65536)

    (Note that 65536 is 2^16 and the can be implemented by taking the upper 16 bits of a 32 bit number.)

  4. M = FIX(K3*C+9.333333333333469 - K3 * 194.3333333333375)

    where K3 = .0326530612244898 to 0.03271028037383177

STEP 7 Calculate the value of F, which is the number of days in the preceding months in the current year, using ONE of the following methods:

  1. F is the value of a vector indexed by M. This vector has values 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337. (M has values that range from 3 through 14.) This method is usually the fastest method and often takes less computer memory to implement.

  2. F = (153*M-457)\5

  3. F = (979*M-2918)\32
    This allows a shift to carry out the division.

  4. If real arithmetic is desired,
    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. Either FIX or the greatest integer function can be used.

STEP 8 The Gregorian date's day of the month is

STEP 9 Convert the month and year to a calendar starting January 1, using ONE of the following methods:

This calculation is valid for any Julian Day Number including negative JDN and produces a Gregorian date (or possibly a proleptic Gregorian date).

Example

The following sequence calculates Gregorian year Y, month M, and day D from a Julian Day Number:

Z = INT(JD - 1721118.5) step 1
R = JD - 1721118.5 - Z step 1
G = Z - .25 used in later steps
A = INT(G / 36524.25) step 2
B = A - INT(A / 4) part of step 3
year = INT((B+G) / 365.25) part of step 3 and step 4
C = B + Z - INT(365.25 * year) step 5
month = FIX((5 * C + 456) / 153) step 6
day = C - FIX((153 * month - 457) / 5) + R step 7 and 8
IF month > 12 THENstep 9
       year = year + 1step 9
       month = month - 12step 9
END IFstep 9

3.2.2 Julian Day number to Julian Date

The previous algorithm development section justifies the following general algorithm forms for converting a Julian Day Number into a Julian Date. In this description:

STEP 1 Let JD be the Julian Day Number. Calculate

    Z = INT(JD - 1721116.5)

    R = the fractional part of JD - 1721116.5 = (JD - 1721116.5) - Z

STEP 2 Calculate the value of Y, the year in a calendar whose years start on March 1:

STEP 3 Calculate the value of the day count in the current year:

C = Z - INT(365.25*Y)

STEP 4 Calculate the value of the month in the current year using ONE of the following:

  1. M = FIX((5*C + 456)/ 153)

  2. M = FIX((535*C + 48950)/ 16384)

    (Note that 16384 is 2^14 and the division can be implemented with shifts if the number has a binary representation.)

  3. M = FIX((2140*C + 195800)/ 65536)

    (Note that 65536 is 2^16 and the can be implemented by taking the upper 16 bits of a 32 bit number.)

  4. M = FIX(K3*C+9.333333333333469 - K3 * 194.3333333333375)

    where K3 = .0326530612244898 to 0.03271028037383177

STEP 5 Calculate the value of F, which is the number of days in the preceding months in the current year, using ONE of the following methods:

  1. F is the value of a vector indexed by M. This vector has values 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337. (M has values that range from 3 through 14.) This method is usually the fastest method and often takes less computer memory to implement.

  2. F = (153*M-457)\5

  3. F = (979*M-2918)\32
    This allows a shift to carry out the division.

  4. If real arithmetic is desired,
    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. Either FIX or the greatest integer function can be used.

STEP 6 The Julian date's day of the month is

STEP 7 Convert the month and year to a calendar starting January 1, using ONE of the following methods:

This calculation is valid for any Julian Day Number including negative JDN and produces a Julian date (or possibly a proleptic Julian date).

Example

The following sequence calculates Julian year Y, month M, and day D from a Julian Day Number:

Z = INT(JD - 1721116.5) step 1
R = JD - 1721116.5 - Z step 1
year = INT((Z -0.25) / 365.25) step 2
C = Z - INT(365.25 * year) step 3
month = FIX((5 * C + 456) / 153) step 4
day = C - FIX((153 * month - 457) / 5) + R step 5 and 6
IF month > 12 THENstep 7
       year = year + 1step 7
       month = month - 12step 7
END IFstep 7


AESIR RESEARCH HOME PAGE

LAST MODIFIED: October 11, 2005