In astronomical formulas that contain a date, it is not convenient to write that date as a combination of years, months, and days, especially because not all years have the same number of days and not all months have the same number of days. It is much more convenient to measure the date as the number of days since some fixed day. The Julian Day Number or Julian Date (JD) is much used for this in astronomy. This page explains how you can translate a date from the Gregorian calendar to the Julian Date, or the other way around.
There are many different algorithms in use for converting between calendar dates and day numbers. The only thing that counts is that they provide the correct answers for all day numbers and calendar dates. If there is only a limited number of input values and possible outcomes (for example for calculating the month number and day-within-the-month number from the day-within-the-year number), then you can usually find many different algorithms that all give just the right answers for those particular values (but perhaps very different answers for all other input values), even if there is no logical connection between that algorithm and the calendar. In such a case there is often also little or no logical connection between the algorithm that converts from date to day number and the algorithm that converts from day number to date, but the algorithms may be shorter then.
About every algorithm you should know for which input values it was designed to work. Some calendar algorithms only work well with positive numbers and give wrong results for negative years or negative day numbers. The algorithms I give below are designed to work for all years (including negative ones), all months between 1 and 12, all monthly day numbers between 1 and 31, and for all Julian Day Numbers (including negative ones).
In the formulas given below, many numbers are rounded to a nearby whole number. It is important that those numbers get rounded in the right direction. Whole numbers are already rounded, so those don't change.
The types of rounding that we use here are downward rounding to the
nearest whole number (for x this is indicated by
⌊x⌋) or upward rounding to the nearest whole number
(⌈x⌉). The standard rounding function on calculators
usually rounds to the nearest whole number (our notation for that is
[x]) and the standard conversion from a fractional
number to a whole number in a computer language is usually by rounding
in the direction of zero (our notation for that is
trunc(x)). We do not want those kinds of rounding
here! The below table shows these three different kinds of rounding
for some values.
x | ⌊x⌋ | [x] | trunc(x) | ⌈x⌉ |
| −5 | −5 | −5 | −5 | −5 |
| −4.9 | −5 | −5 | −4 | −4 |
| −4.2 | −5 | −4 | −4 | −4 |
| −4 | −4 | −4 | −4 | −4 |
| −0.2 | −1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0.2 | 0 | 0 | 0 | 1 |
| 4 | 4 | 4 | 4 | 4 |
| 4.2 | 4 | 4 | 4 | 5 |
| 4.9 | 4 | 5 | 4 | 5 |
| 5 | 5 | 5 | 5 | 5 |
All months in the Julian and Gregorian calendars have the same length in each year, except for February: that month has 29 days in a leap year, instead of 28 days. It is easier to calculate if the deviating thing is at the very end of the period, so we work with periods of a year that begin with March 1st and that run until just before the next March 1st. Let's call that the calculation year. If there is a leap day, then it comes at the very end of the calculation year. For convenience we keep calling March month number 3 (of the calculation year), so then January becomes month number 13 and February becomes month number 14. We regard January and February of a particular calendar year as the last two months of the preceding calculation year.
The lengths of the months in the calculation year then are:
| length | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 | 31 | 31 | 28 of 29 |
| month | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Jan | Feb |
| number | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
We see two successive sets of 31-30-31-30-31 days (March through July, and then August through December) and then part of a third such set (January and February), but that one stops after 28 or 29 days in the second month of the set. Such a period of 31-30-31-30-31 is 153 days long, so we can say that the year is divided into periods of 153 days, and each such a period has the same sequence of month lengths, until the year is full.
Within such a period of 153 days we see three repeats of the sequence 31-30 days (61 days), again with the last repeat truncated (because that one only contains one month). And within such a period of 61 days we see a repeat of periods (months) of 31 days, again with the last period truncated, because that one contains only 30 days.
All in all we can say that the day number n since the
beginning of the calculation year (March 1 has n = 1),
and the month number m in the calculation year
(m = 3 through 12 for March through December, and 13
and 14 for the immediately following January and February) are equal
to
(Eq. 1) n − 1 = Q₁ = 153*c₃ + 61*c₂ + 31*c₁ + d − 1
(Eq. 2) m − 3 = Q₂ = 5*c₃ + 2*c₂ + c₁
where all c numbers are whole numbers greater than or
equal to 0, and c₁ is less than 2, c₂ is
less than 5, and c₃is less than 3.
Here are the results of calculations for the first day (d =
1) of each month from the calculation year.
m | c₃ | c₂ | c₁ | n | length |
|---|---|---|---|---|---|
| 3 | 0 | 0 | 0 | 1 | 31 |
| 4 | 0 | 0 | 1 | 32 | 30 |
| 5 | 0 | 1 | 0 | 62 | 31 |
| 6 | 0 | 1 | 1 | 93 | 30 |
| 7 | 0 | 2 | 0 | 123 | 31 |
| 8 | 1 | 0 | 0 | 154 | 31 |
| 9 | 1 | 0 | 1 | 185 | 30 |
| 10 | 1 | 1 | 0 | 215 | 31 |
| 11 | 1 | 1 | 1 | 246 | 30 |
| 12 | 1 | 2 | 0 | 276 | 31 |
| 13 | 2 | 0 | 0 | 307 | 31 |
| 14 | 2 | 0 | 1 | 338 |
And here is the calculation for n = 366: Then Q₁
= 365 so c₃ = 2, c₂ = 0, c₁ = 1 and d −
1 = 28, so d = 29. Then we also have Q₂
= 5*2 + 2*0 + 1 = 11 so m = 14. n =
366 corresponds to February 29th.
The trick is to find the right c₁, c₂,
and c₃ that go with the given Q₁ (if you
want to go from day number to date) or Q₂ (if you want
to go from date to day number).
Here is a recipe, based on an example. Which day number
n corresponds to September 7th (d = 7, m =
9)? Then equation 2 becomes:
m − 3 = 9 − 3 = 6 = Q₂ = 5*c₃ + 2*c₂ + c₁
We must now figure out how many times the three periods (5, 2, 1) fit
into Q₂: those are then the c₃, c₂, c₁
that we can enter into equation 1 to find n.
We begin with the largest period: 5. That one fits into Q₂ =
6 1 time (so c₃ = 1) and then 6 − 5 = 1
remains. Now we try the next biggest period: 2. That one is greater
than what was left, so it fits 0 times (c₂ = 0) and
we're still left with 1. That one must then be equal to
c₁, so we find c₃ = 1, c₂ = 0, c₁ = 1
and hence 6 = Q₂ = 5*1 + 2*0 + 1, which is correct.
Now we enter those cs (and also d = 7)
into equation 1: n − 1 = Q₁ = 153*1 + 61*0 + 31*1 + 7
− 1 = 190 and so n = 191.
Now we go in the opposite direction. Which month m and
day d correspond to n = 360? Then
equation 1 becomes n − 1 = 360 − 1 = 359 = Q₁ = 153*c₃
+ 61*c₂ + 31*c₁ + d − 1.
First we check how many times the largest period 153 fits into
Q₁ = 359. 153 fits 2 times (so c₃ = 2)
into 359, and 359 − 2*153 = 53 remains. How many times does the next
biggest period 61 fit into 53? That fits 0 times (c₂ =
0) and we keep the 53. How often does the last period 31 fit
into 53? That fits 1 time (c₁ = 1) and we're left with
53 − 1*31 = 22. That 22 must then be equal to d − 1,
so d = 23.
We now enter the c₃ = 2, c₂ = 0, c₁ = 1 into equation
2 and find m − 3 = Q₂ = 5*2 + 2*0 + 1 = 11
so m = 14. Day number n = 360 of the
calculation year (which begins with March 1st) corresponds to the 23rd
day of month 14 (= February), or February 23rd.
In a bit more mathematical language, the algorithm for "decomposing into periods" goes as follows. Suppose that
(Eq. 3) x = p₁*c₁ + p₂*c₂ + … + pn*cn + x₀
and that you know x and all pi and
want to calculate ci and x₀. We
assume that all pi are greater than 0. If a
particular pi is negative, then remove its minus
sign. We sort the pi so that p₁ < p₂ <
p₃ < … < pn. Then set
(Eq. 4) xn = x
and then for every i from n through 1:
(Eq. 5) ci = ⌊xi/pi⌋
(Eq. 6) x(i−1) = xi − ci*pi = xi mod pi
d = 7, m = 9) and equation 2 we
find x = 6 = m − 3 and p₃ = 5, p₂ = 2, p₁ =
1. Then x₃ = x = 6, c₃ = ⌊x₃/p₃⌋ =
⌊6⁄5⌋ = 1, x₂ = x₃ − c₃p₃ = 6 − 1*5 = 1 = 6 mod 5 = x₃
mod p₃, c₂ = ⌊x₂/p₂⌋ = ⌊1⁄2⌋ = 0, x₁ =
x₂ − c₂p₂ = 1 − 0*2 = 1, c₁ = ⌊x₁/p₁⌋ = ⌊1⁄1⌋ =
1 and x₀ = x₁ − c₁p₁ = 0.
So c₃ = 1, c₂ = 0, c₁ = 1 like we found in the previous
example.
Warning! Don't remove the − 1 from the left hand side
and right hand side of equation 1, otherwise the
cs aren't correct anymore in some cases, such as for
n = 31. Equation 1 then yields n − 1 =
30 = Q₁ = 153*0 + 61*0 + 31*0 + d − 1 so d = 31
and (from equation 2) m − 3 = 5*0 + 2*0 + 0 =
0 so m = 3, which means March 31st. If the
− 1 are removed then equation 1 yields
(Eq. 7) n = 153*c₃ + 61*c₂ + 31*c₁ + d (wrong!)
which in this case yields 31 = 153*0 + 61*0 + 31*1 + 0
and then equation 2 leads to m − 3 = 5*0 + 2*0
+ 1 = 1 so m = 4, which means April 0th ― which
is incorrect.
Another method is to find a straight line that (with rounding) yields the right results. If there are only two different month lengths that differ by only one day (except that the very last month may be shorter), then you can try to find such a line.
First we prepare some formulas. Let
(Eq. 8) y = y₀ + z
(Eq. 9) y₀ = ⌊px⌋
for whole numbers x, y, z, with p ≥ 1 and
0 ≤ z ≤ ⌈p⌉. Then when x increases by
one, then y₀ increases by either ⌊p⌋ or
⌈p⌉.
In the other direction we have
(Eq. 10) x = ⌈(y + 1)/p⌉ − 1
(Eq. 11) z = y − ⌊px⌋
where one or more values of y yield the same
x. With these formulas, y = 0
corresponds to x = 0, z = 0.
That these pairs of formulas are each other's inverse can be seen as follows. First we rewrite equation 9 to
(Eq. 12) y₀ = px − δ
where δ is the difference that must be subtracted from
px to find the nearest whole number, with 0 ≤ δ
< 1. If we insert this rewritten formula into 10
with also z = 0 then we find
(Eq. 13) x = ⌈(px − δ + 1)/p⌉ − 1 = ⌈x + (1 − δ)/p⌉ − 1 = x − 1 + ⌈(1 −
δ)/p⌉ = x
because 0 ≤ δ < 1 so 0 < 1 − δ ≤ 1
so 0 < (1 − δ)/p ≤ 1/p ≤ 1 so ⌈(1 − δ)/p⌉ =
1.
If y increases or decreases then at a certain point the
corresponding x (from equation 8) changes,
too. Suppose that a certain x = x' corresponds to a
certain y₀ = y₀'. We want the change in
x to occur just before y₀', i.e., that
if y = y₀' − 1 then x = x' − 1.
If y = y₀' − 1 then we find from equations 10
and 12 that
(Eq. 14) x = ⌈(y₀' − 1 + 1)/p⌉ − 1 = ⌈y₀'/p⌉ − 1 = ⌈(px₀ − δ)/p⌉ − 1 = x₀
− 1 + ⌈−δ/p⌉ = x₀ − 1
because 0 ≤ δ < 1 so −1 < −δ ≤ 0
so ⌈−δ/p⌉ = 0.
We have now shown that the shift to another x occurs
just before the y₀ that follows from equation
9.
It is inconvenient that two different kinds of rounding are used in
these formulas. Rounding up (⌈⌉) is not often available on electronic
calculators. ⌈q⌉ = ⌊q⌋ + 1 except if q
is a whole number, because then ⌈q⌉ = ⌊q⌋. So, if we
can arrange things such that q cannot be a whole number
(for the input values that interest us), then we can replace equation
10 by
(Eq. 15) x = ⌊(y + 1)/p⌋ ((y + 1)/p not a whole number)
If p is a rational number, p = f/g with
f, g whole numbers, then (y + 1)/p can
be a whole number (if y + 1 is a multiple of
f), and (y + 1)/p can differ from a
whole number by 1/f or a multiple of that, but cannot
differ less than that from a whole number. If we shift (y +
1)/p by an amount greater than 0 but less than
1/f, then it can never be a whole number anymore. We
choose a shift of half of 1/f. The shift must be
downward. Then equation 10 yields
(Eq. 16) x = ⌈(y + 1)/p − (1/(2f))⌉ − 1 = ⌈(2*g*y + 2*g − 1)/(2*f)⌉ −
1
and equation 15
(Eq. 17) x = ⌊(y + 1)/p − (1/(2*f))⌋ = ⌊(2*g*y + 2*g −
1)/(2*f)⌋
Warning! Equations 16 and 17 are only
correct for all y if p is a whole number
or ratio (i.e., a rational number). If p is not a
whole number or a ratio (i.e., if it is transcendent) then these
formulas are only valid for a limited range of y.
Here is an example with p = 4⁄3. xa
stands for x from equation 10,
xb for x from equation
16, and xc for x from
equation 17. Equation 16 then becomes
x = ⌊(6*y + 5)/8⌋.
y | xa | xb | xc |
| 0 | ⌈0.75⌉ − 1 = 0 | ⌈0.625⌉ − 1 = 0 | ⌊0.625⌋ = 0 |
| 1 | ⌈1.5⌉ − 1 = 1 | ⌈1.375⌉ − 1 = 1 | ⌊1.375⌋ = 1 |
| 2 | ⌈2.25⌉ − 1 = 2 | ⌈2.125⌉ − 1 = 2 | ⌊2.125⌋ = 2 |
| 3 | ⌈3⌉ − 1 = 2 | ⌈2.875⌉ − 1 = 2 | ⌊2.875⌋ = 2 |
Now we are ready to apply these formulas to the calendar.
If m is the month number (m = 3 for the
first month of the calculation year) and d is the day
number within the month (d = 1 for the first day of the
month) and n is the day number within the calculation
year (n = 1 for the first day of the calculation year),
then
(Eq. 18) n = ⌊p*(m + a)⌋ − ⌊p*(3 + a)⌋ + d
(Eq. 19) m = ⌈(n + ⌊p*(3 + a)⌋)/p⌉ − a − 1
(Eq. 20) d = n − ⌊p*(m + a)⌋ + ⌊p*(3 + a)⌋
These formulas follow from equation 8ff if we set x
= m + a, y = n + ⌊p*(3 + a)⌋ − 1, and z
= d − 1.
The trick is now to find p and a that
yield the correct month lengths. The p determines the
succession of month lengths (and the average month length, for an
infinite number of months), and a determines which of
those months gets to be number 1.
If you allow m to run through all whole numbers, and if
p is a rational number, then the sequence of month
lengths keeps repeating itself. If p = f/g with whole
numbers f, g, then the sequence of month lengths
repeats every g months. If p cannot be
written as a ratio (i.e., it is a transcendental number), then the
sequence of month lengths does not repeat itself in the long run.
For the Julian and Gregorian calendars, the month lengths are 30 or 31
days (except for February, which is shorter), so p must
be between 30 and 31. We need two successive months with 31 days
(e.g., July and August), so p must be greater than
30.5. It turns out that p = 30.6 = 153⁄5 and a
= 1 yield the right sequence of month lengths for
m between 3 and 14 (inclusive). This means
(Eq. 21) n = ⌊30.6*(m + 1)⌋ + d − 122 = ⌊153*(m + 1)/5⌋ + d −
122 = ⌊(153*m − 457)/5⌋ + d
(Eq. 22) m = ⌊(n + 122)/30.6001⌋ − 1
(Eq. 23) m = ⌊(10*(n + 121) + 10 − 1)/306⌋ − 1 = ⌊(10*n +
913)/306⌋
(Eq. 24) d = n + 122 − ⌊30.6*(m + 1)⌋ = n + 122 − ⌊153*(m +
1)/5⌋ = n − ⌊(153*m − 457)/5⌋
In equation 22 the divisor is 30.6001 rather than 30.6, to
ensure that the number to be rounded is never already a whole number.
Other values greater than 30.6 but not greater than 30.615 also yield
the right results (for m between 3 and 14). If you
used 30.6 in equation 22, then you'd get incorrect results for
example when n = 31. In equations 21 and
24 you can also use 30.6001 instead of 30.6.
Which day number n corresponds to September 7th
(d = 7, m = 9)? Then equation 21 yields:
n = ⌊30.6*(m + 1)⌋ + d − 122 = ⌊30.6*10⌋ + 7 − 122 = ⌊306⌋ + 7
− 122 = 191
n = ⌊(153*9 − 457)/5⌋ + 7 = ⌊920⁄5⌋ + 7 = 191
And now we go in the other direction. Which month number
m and day number d correspond with
n = 360? Then equation 22 yields
m = ⌊(360 + 122)/30.6001⌋ − 1 = ⌊15.75158⌋ − 1 = 15 − 1 =
14
and equation 23
m = ⌊(10*360 + 913)/306⌋ = ⌊4513⁄306⌋ = 14
and equation 24
d = 360 + 122 − ⌊30.6*15⌋ = 482 − ⌊459⌋ = 482 − 459 =
23
d = 360 − ⌊(153*14 − 457)/5⌋ = 360 − ⌊1685⁄5⌋ = 360 − 337 =
23
so we find m = 14 (= February) and d =
23, i.e., February 23rd.
In the Julian calendar, every three regular years of 365 days are followed by a leap year of 366 days. This period of four years contains 3*365 + 366 = 1461 days. Each period of four years has the same sequence of months with their month lengths. Now we have the opposite problem to the one we faced for the months: During the earlier calculations with months the last period was truncated, but now that we calculate with years the last period (the 4th year) gets longer. If we're not careful, then the extra bit (the leap day) is regarded as a very short extra period, rather than belonging at the end of the previous period.
If we follow the same ideas as for the months, then we'd have for the
calculation year number j and day number
N since the previous leap day:
(Eq. 25) N − 1 = 1461*c₅ + 365*c₄ + n − 1
(Eq. 26) j = 4*c₅ + c₄
where c₄ is less than 4. But if we apply this to
N = 1461 (the leap day at the very end of the period)
then we find c₅ = 0, c₄ = 4, n = 1, j = 4 (which
corresponds to the first day of year 4) instead of c₅ = 0, c₄ =
3, n = 366, j = 3 (the last day of year 3).
We want to keep the results from equation 25 for the first
1460 days, but to have c₄ for day number 1461 equal to
3 instead of 4. We manage that by applying a correction to
c₄ and n. If you calculate
c₄ and n first and only then apply the
correction, then that correction is
(Eq. 27) n → n + 365*⌊c₄/4⌋
(Eq. 28) c₄ → c₄ − ⌊c₄/4⌋
If you first calculate c₄, then apply the correction to
c₄, and only then calculate n (based on
the corrected c₄), then you don't have to correct
n any further.
These corrections should be applied only when we go from day number to calendar date.
Here are the calculations for March 1th of the Julian calculation
years 2007−2012. Warning: Because we regard January and February from
the current calendar year as being at the end of the previous
calculation year, the leap day from calendar year 2008 falls at the
end of calculation year 2007 (= j).
j | c₅ | c₄ | N | length |
|---|---|---|---|---|
| 2007 | 501 | 3 | 733057 | 366 (leap year) |
| 2008 | 502 | 0 | 733423 | 365 |
| 2009 | 502 | 1 | 733788 | 365 |
| 2010 | 502 | 2 | 734153 | 365 |
| 2011 | 502 | 3 | 734518 | 366 (leap year) |
| 2012 | 503 | 0 | 734884 |
Here are the calculations from day number to calendar date for three days around the leap day 29 February 2008:
N | c₅ | c₄ | n | j |
|---|---|---|---|---|
| 733421 | 501 | 3 | 365 | 2007 |
| 733422 | 501 | 4 → 3 | 1 → 366 | 2007 |
| 733423 | 502 | 0 | 1 | 2008 |
Here are the calculations for March 1th of the Julian calculation
years 2007−2012. Warning: Because we regard January and February from
the current calendar year as being at the end of the previous
calculation year, the leap day from calendar year 2008 falls at the
end of calculation year 2007 (= j).
j | N | length |
|---|---|---|
| 2007 | 733057 | 366 (leap year) |
| 2008 | 733423 | 365 |
| 2009 | 733788 | 365 |
| 2010 | 734153 | 365 |
| 2011 | 734518 | 366 (leap year) |
| 2012 | 734884 |
Here are the calculations from day number to calendar date for three days around the leap day 29 February 2008:
N | j | n |
|---|---|---|
| 733421 | 2007 | 365 |
| 733422 | 2007 | 366 |
| 733423 | 2008 | 1 |
De Gregoriaanse kalender is als de Juliaanse, maar heeft twee extra regels voor welke jaren schrikkeljaren zijn, en daarmee twee grotere perioden in de berekeningen. De eerste extra regel betekent dat in elke periode van 100 jaar één schrikkeldag wordt overgeslagen. Zo'n periode van 100 jaar bevat dan 24*1461 + 1460 = 25*1461 − 1 = 36524 dagen. De twee extra regel betekent dat elke 400 jaar toch weer een extra schrikkeldag wordt ingelast. Zo'n periode van 400 jaar bevat dan 3*36524 + 36525 = 146097 dagen.
The Gregorian calendar is like the Julian one, but has two extra rules for which years are leap years, which means it has two greater periods in its calculations. The first extra rule means that from every period of 100 years one leap day gets omitted. Such a period of 100 days then contains 24*1461 + 1460 = 25*1461 − 1 = 36524 days. The second extra rule means that every period of 400 years gets one extra leap day again. Such a period of 400 years then contains 3*36524 + 36525 = 146097 days.
All in all we find for the calculation year number j
and the day number N of March 0 of the calculation
year:
(Eq. 29) N = 146097*c₇ + 36524*c₆ + 1461*c₅ + 365*c₄
(Eq. 30) j = 400*c₇ + 100*c₆ + 4*c₅ + c₄
but when we calculate from day number to calendar date then we have to apply leap day corrections again. In this case we have to apply two corrections, because both the periods of 400 years (relative to that of 100 years) and the period of 4 years (relative to that of 1 year) contain an extra (leap) day. In that case it is better to rewrite the formulas to
(Eq. 31) N = 146097*c₇ + 36524*c₆ + n₁
(Eq. 32) n₁ → n₁ + 36524*⌊c₆/4⌋
(Eq. 33) c₆ → c₆ − ⌊c₆/4⌋
(Eq. 34) n₁ = 1461*c₅ + 365*c₄ + n₂
(Eq. 35) n₂ → n₂ + 365*⌊c₄/4⌋
(Eq. 36) c₄ → c₄ − ⌊c₄/4⌋
(Eq. 37) j = 400*c₇ + 100*c₆ + 4*c₅ + c₄
Here c₄ is eventually less than 4, c₅
less than 25 and c₆ less than 4.
Here are the calculations for March 0 of Gregorian calculation years
2007-2012. Warning: Because we regard January and February from the
current calendar year as being at the end of the previous calculation
year, the leap day from calendar year 2008 falls at the end of
calculation year 2007 (= j).
j | c₇ | c₆ | c₅ | c₄ | N | length |
|---|---|---|---|---|---|---|
| 2007 | 5 | 0 | 1 | 3 | 733041 | 366 (leap year) |
| 2008 | 5 | 0 | 2 | 0 | 733407 | 365 |
| 2009 | 5 | 0 | 2 | 1 | 733772 | 365 |
| 2010 | 5 | 0 | 2 | 2 | 734137 | 365 |
| 2011 | 5 | 0 | 2 | 3 | 734502 | 366 (leap year) |
| 2012 | 5 | 0 | 3 | 0 | 734868 |
Here are the calculations from day number to calendar date for three days around leap day 29 February 2008:
N | c₇ | c₆ | n₁ | c₅ | c₄ | n₂ | j | m | d |
|---|---|---|---|---|---|---|---|---|---|
| 733405 | 5 | 0 | 2920 | 1 | 3 | 364 | 2007 → 2008 | 14 → 2 | 28 |
| 733406 | 5 | 0 | 2921 | 1 | 4 → 3 | 0 → 365 | 2007 → 2008 | 14 → 2 | 29 |
| 733407 | 5 | 0 | 2922 | 2 | 0 | 0 | 2008 | 3 | 1 |
and here for three days around leap day 29 February 2000:
N | c₇ | c₆ | n₁ | c₅ | c₄ | n₂ | j | m | d |
|---|---|---|---|---|---|---|---|---|---|
| 730483 | 4 | 3 | 36523 | 24 | 3 | 364 | 1999 → 2000 | 14 → 2 | 28 |
| 730484 | 4 | 4 → 3 | 0 → 36524 | 24 | 4 → 3 | 0 → 365 | 1999 → 2000 | 14 → 2 | 29 |
| 730485 | 5 | 0 | 0 | 0 | 0 | 0 | 2000 | 3 | 1 |
All together we now find:
(Eq. 38) J − c₀ = 146097*c₇ + 36524*c₆ + 1461*c₅ + 365*c₄ + 153*c₃ + 61*c₂ +
31*c₁ + d − 1
(Eq. 39) m − 3 = 5*c₃ + 2*c₂ + c₁
(Eq. 40) j = 400*c₇ + 100*c₆ + 4*c₅ + c₄
but we have to add in the corrections for leap days, if we are calculating calendar dates from day numbers. In that case it is better to rewrite the previous formulas to
(Eq. 41) J − c₀ = 146097*c₇ + 36524*c₆ + n₁
(Eq. 42) n₁ → n₁ + 36524*⌊c₆/4⌋
(Eq. 43) c₆ → c₆ − ⌊c₆/4⌋
(Eq. 44) n₁ = 1461*c₅ + 365*c₄ + n₂
(Eq. 45) n₂ → n₂ + 365*⌊c₄/4⌋
(Eq. 46) c₄ → c₄ − ⌊c₄/4⌋
(Eq. 47) n₂ = 153*c₃ + 61*c₂ + 31*c₁ + d − 1
(Eq. 48) m − 3 = 5*c₃ + 2*c₂ + c₁
(Eq. 49) j = 400*c₇ + 100*c₆ + 4*c₅ + c₄
Here c₀ is a number that ties the formulas to the
beginning of the Julian day count. It is the Julian day number of
March 1st of the year 0, in the Julian and Gregorian proleptic
calendars.
All cs are whole numbers. Further restrictions are
listed in the following table.
c₀ | c₁ | c₂ | c₃ | c₄ | c₅ | c₆ | c₇ | |
| Julian | 1721117.5 | ≥0, <2 | ≥0, <5 | ≥0, <3 | ≥0, <4 | free | 0 | 0 |
| Gregorian | 1721119.5 | ≥0, <2 | ≥0, <5 | ≥0, <3 | ≥0, <4 | ≥0, < 25 | ≥0, <4 | free |
The algorithm to calculate a Julian Day Number J from a
Gregorian date (calendar year j, calendar month
m (1 ≤ m ≤ 12), calendar day
d) is:
m < 3, then replace m by
m + 12 and j by j −
1.(Eq. 50) c₇ = ⌊j/400⌋
(Eq. 51) x₆ = j − 400*c₇ = j mod 400
(Eq. 52) c₆ = ⌊x₆/100⌋
(Eq. 53) x₅ = x₆ − 100*c₆ = x₆ mod 100
(Eq. 54) c₅ = ⌊x₅/4⌋
(Eq. 55) c₄ = x₅ − 4*c₅ = x₅ mod 4
(Eq. 56) c₃ = ⌊(m − 3)/5⌋
(Eq. 57) x₂ = m − 3 − 5*c₃ = (m − 3) mod 5
(Eq. 58) c₂ = ⌊x₂/2⌋
(Eq. 59) c₁ = x₂ − 2*c₂ = x₂ mod 2
(Eq. 60) J = 146097*c₇ + 36524*c₆ + 1461*c₅ + 365*c₄ + 153*c₃ +
61*c₂ + 31*c₁ + d + 1721118.5
For example: what is the Julian Day Number for 7 September 2010 on the
Gregorian calendar? Then j = 2010, m = 9, d = 7 so
c₇ = 5, x₆ = 10, c₆ = 0, x₅ = 10, c₅ = 2, c₄ = 2, c₃ = 1, x₂ =
1, c₂ = 0, c₁ = 1 and then J = 146097*5 + 36524*0 +
1461*2 + 365*2 + 153*1 + 61*0 + 31*1 + 7 + 1721118.5 =
2455446.5.
The algorithm to calculate a Gregorian date (calendar year
j, calendar month m (1 ≤
m ≤ 12), calendar day d) from a Julian
Day Number J is:
(Eq. 61) c₇ = ⌊(J − 1721119.5)/146097⌋
(Eq. 62) x₆ = J − 1721119.5 − 146097*c₇ = (J − 1721119.5) mod 146097
(Eq. 63) c₆ = ⌊x₆/36524⌋
(Eq. 64) c₆ → c₆ − ⌊c₆/4⌋
(Eq. 65) x₅ = x₆ − 36524*c₆
(Eq. 66) c₅ = ⌊x₅/1461⌋
(Eq. 67) x₄ = x₅ − 1461*c₅ = x₅ mod 1461
(Eq. 68) c₄ = ⌊x₄/365⌋
(Eq. 69) c₄ → c₄ − ⌊c₄/4⌋
(Eq. 70) x₃ = x₄ − 365*c₄
(Eq. 71) c₃ = ⌊x₃/153⌋
(Eq. 72) x₂ = x₃ − 153*c₃ = x₃ mod 153
(Eq. 73) c₂ = ⌊x₂/61⌋
(Eq. 74) x₁ = x₂ − 61*c₂ = x₂ mod 61
(Eq. 75) c₁ = ⌊x₁/31⌋
(Eq. 76) x₀ = x₁ − 31*c₁ = x₁ mod 31
(Eq. 77) j = 400*c₇ + 100*c₆ + 4*c₅ + c₄
(Eq. 78) m = 5*c₃ + 2*c₂ + c₁ + 3
(Eq. 79) d = x₀ + 1
m > 12, then replace m by
m − 12 and j by j +
1.For example, what is the Gregorian calendar date that corresponds to
Julian Day Number 2455446.5? Then J = 2455446.5 so
c₇ = 5, x₆ = 3842, c₆ = 0, x₅ = 3842, c₅ = 2, x₄ = 920, c₄ = 2,
x₃ = 190, c₃ = 1, x₂ = 37, c₂ = 0, x₁ = 37, c₁ = 1, x₀ = 6 and
then j = 2010, m = 9, d = 7, so the date is 7 September
2010.
The algorithm to calculate a Julian Day Number J from a
Julian date (calendar year j, calendar month
m (1 ≤ m ≤ 12), calendar day
d is:
m < 3, then replace m by
m + 12 and j by j −
1.(Eq. 80) c₅ = ⌊j/4⌋
(Eq. 81) c₄ = j − 4*c₅ = x₅ mod 4
(Eq. 82) c₃ = ⌊(m − 3)/5⌋
(Eq. 83) x₂ = m − 3 − 5*c₃ = (m − 3) mod 5
(Eq. 84) c₂ = ⌊x₂/2⌋
(Eq. 85) c₁ = x₂ − 2*c₂ = c₂ mod 2
(Eq. 86) J = 1461*c₅ + 365*c₄ + 153*c₃ + 61*c₂ + 31*c₁ + d +
1721116.5
For example, what is the Julian Day Number corresponding to 7
September 2010 on the Julian calendar? Then j = 2010, m = 9, d
= 7 so c₅ = 502, c₄ = 2, c₃ = 1, x₂ = 1, c₂ = 0, c₁ =
1 and then J = 1461*502 + 365*2 + 153*1 + 61*0 + 31*1 +
7 + 1721116.5 = 2455459.5.
The algorithm to convert from a Julian Day Number J to
a Julian date (calendar year j, calendar month
m (1 ≤ m ≤ 12), calendar day
d) is:
(Eq. 87) c₅ = ⌊(J − 1721117.5)/1461⌋
(Eq. 88) x₄ = J − 1721117.5 − 1461*c₅ = (J − 1721117.5) mod 1461
(Eq. 89) c₄ = ⌊x₄/365⌋
(Eq. 90) c₄ → c₄ − ⌊c₄/4⌋
(Eq. 91) x₃ = x₄ − 365*c₄
(Eq. 92) c₃ = ⌊x₃/153⌋
(Eq. 93) x₂ = x₃ − 153*c₃ = x₃ mod 153
(Eq. 94) c₂ = ⌊x₂/61⌋
(Eq. 95) x₁ = x₂ − 61*c₂ = x₂ mod 61
(Eq. 96) c₁ = ⌊x₁/31⌋
(Eq. 97) x₀ = x₁ − 31*c₁ = x₁ mod 31
(Eq. 98) j = 4*c₅ + c₄
(Eq. 99) m = 5*c₃ + 2*c₂ + c₁ + 3
(Eq. 100) d = x₀ + 1
m > 12, then replace m by
m − 12 and j by j +
1.For example, what is the Julian date corresponding to Julian Day
Number 2455459.5? Then J = 2455459.5 so c₅ =
502, x₄ = 920, c₄ = 2, x₃ = 190, c₃ = 1, x₂ = 37, c₂ = 0, x₁ = 37, c₁
= 1, x₀ = 6 and then j = 2010, m = 9, d = 7, so
the date is 7 September 2010.
If you want to know how many days there are between two dates, then you can calculate that exactly by subtracting the Julian Day numbers of the two dates. If you are satisfied with a possible error of a few days, then you can also estimate it from the difference measured in calendar years, calendar months, and calendar days.
Such information (the number of calendar years, months, and days) is not sufficient to calculate the exact number of days for all calendars, because not every year contains the same number of days as every other year, and not every month contains the same number of days as every other month (in all calendars).
Let's assume that the second date is j calendar years
and m calendar months and d calendar
days later than the first date (both in the same calendar, the
Gregorian Calendar or the Jewish Calendar or the administrative
Islamic Calendar), where you just subtract the year number, month
number, and day number of the second date from those of the first date
(which must be later). The variable j may be positive
or zero, but not negative. The variables m and
d may be positive or zero or negative, but
m must not correspond to more than one calendar year,
and d must not correspond to more than one calendar
month. For the Jewish calendar we define Tishri to be month number 1
and define Adar II to belong to month number 6 together with Adar (so
that month number 6 may contain up to 59 days). For the Egyptian
calendar we count the last 5 days of the year as a 13th month. Then
you can estimate the number n of days between those two
dates using the formula
(Eq. 101) n = ⌊a j + b m + c d⌋
with a, b, and c from the
following table:
a | b | c | |Δ|max | σ | p0 | |
|---|---|---|---|---|---|---|
| Gregorian | 365.24 | 30.4 | 1 | 4 | 1.1 | 35 % |
| Jewish | 365.25 | 31.0 | 0.9 | 37 | 12.9 | 3 % |
| Islamic | 354.367 | 29.5 | 1 | 2 | 0.6 | 62 % |
| Egyptian | 365 | 30 | 1 | 0 | 0 | 100 % |
The |Δ|max from the table shows the greatest error
(measured in days) that the formula for that calendar yields (based on
10,000 random test dates) for dates that are not more than 400 years
apart. The sigma shows the standard deviation (say,
the average error, also measured in days). The p0
shows the probability that the estimated number n of
days between the two dates is exactly right.
It is clear that the Egyptian calendar is the most predictable one, because it yields the least mistakes (namely zero). Then comes the administrative Islamic calendar, then the Gregorian calendar (with more variation in the month lengths than the Islamic calendar has), en lastly the Jewish calendar (with variation in the number of months in the year).
An example: How many days are there between 2003-05-25 and 2017-01-17
in the three calendars? Those dates differ by 14 years, −4 months,
and −8 days. In the Gregorian calendar this yields n =
⌊365.24*14 + 30.4*−4 − 8⌋ = ⌊4983.76⌋ = 4983 days. The real
number of days between those two dates is 4986.
In the Jewish calendar this yields n = ⌊365.25*14 + 31.0*−4 +
0.9*−8⌋ = ⌊4982.3⌋ = 4983 days, which happens to be equal to
the real number of days between those two dates in the Jewish
calendar.
In the administrative Islamic calendar this yields n =
⌊354.367*14 + 29.5*−4 − 8⌋ = ⌊4835.138⌋ = 4835 days, which is
equal to the real number of days between those two dates in the
administrative Islamic calendar.
In the Egyptian calendar this yields n = ⌊365*14 + 30*−4 − 8⌋ =
⌊4982⌋ = 4982 days, which is equal to the real number of days
between those two dates in the Egyptian calendar.
http://www.astro.uu.nl/~strous/AA/en/reken/juliaansedag.html;
Last updated: 2009-11-04