Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

Converting Gregorian Date to Gregorian Days

Date: 02/27/2003 at 14:09:39
From: Logan
Subject: Converting Gregorian Date to Gregorian days

I'm trying to convert a Gregorian date (e.g. Feb. 10, 1788) to the 
number of days that has passed since the implementation of the 
Gregorian Calender on October 15, 1582 (this being day 1).

For example October 17th, 1582 would be day 3, and March 3, 2003 would 
be day 153542.

I've converted the number of days from the year inputted to 1583, and 
added 1 day for leap years divisible by 4, subtracted 1 day for years 
ending in 100, and then added 1 day for years divisible by 400, but I 
am having problems adding the months and days of the month, etc.

Any help would be greatly appreciated.


Date: 02/28/2003 at 21:36:27
From: Doctor Fenton
Subject: Re: Converting Gregorian Date to Gregorian days

Hi Logan,

Thanks for writing to Dr. Math.  The simplest way I know to do the
calculation you are looking for is to use the Julian Day system. This 
is a continuous count of days from January 1, 4713 B.C. and,
surprisingly, it is fairly easy to compute.

The following algorithm is adapted from Jean Meeus' "Astronomical 
Formulae for Calculators."  In the following, int(x) means the 
integer (whole number) part of x: int(4.25) = 4; int(-1.7) = -1; etc.

Given a year YYYY, a month MM, and a day D, if the month is January
or February (M=1 or 2), replace let y = YYYY-1 and let m = M+13.
Otherwise, let y = YYYY and m = M+1.

Compute A = int(y/100), and let B = 2 - A + int(A/4).

Then the Julian Day number JD of this date is

   JD = int(365.25*y) + int(30.6001*m) + B + D + 1720995.

For example, for Feb. 28, 2003, YYYY=2003, M=2, and D=28,
so y = 2002, m=15, A = 20, and B = -13, so

   JD = int(365.25*2002) + int(30.6001*15) + 28 - 13 + 1720995
      = int(731230.5) + int(459.0015) + 28 - 13 + 1720995
      = 731230 + 459 + 28 - 13 + 1720995
      = 2452699

while for July 4, 2001, YYYY=2001, M=7, and D= 4, so y = 2001, 
m = 8, A = 20, and again B = -13.  Then

  JD = int(365.25*2001) + int(30.6001*8) + 4 - 13 + 1720995
     = int(730865.25) + int(244.8008) + 4 - 13 + 1720995
     = 2452095.

Day 1 of the Gregorian calendar was Oct. 15, 1582, whose JD is

  JD = 2299161,

so the JD of the last day of the Julian calendar was

  JD = 2299160.

So, compute the JD of the day you are interested in, and subtract
2299160, and that will give you the number of days since the beginning 
of the Gregorian calendar.

If you use this on historical dates, remember that the Gregorian
calendar wasn't adopted everywhere on Oct. 15, 1582.  It wasn't 
adopted in British colonies until about 1752, and in Russia after the 
1917 revolution (which is why it is called the "October Revolution," 
even though it occurred in November in the Gregorian calendar).

This formula only works for Gregorian dates. If you have a Julian
calendar date, i.e. before Oct. 15, 1582 (the previous day had the 
Julian calendar date Oct. 4, 1582, you set B = 0). There's another 
correction for years B.C., but all the Gregorian rules are 
incorporated in this formula.

If you have any questions, please write back and I will try to
explain further. 

- Doctor Fenton, The Math Forum
  http://mathforum.org/dr.math/ 

Date: 06/06/2003 at 06:36:55
From: David
Subject: What about BC?

Is there an additional correction for years B.C.? 

-David

Date: 06/06/2003 at 17:36:35
From: Doctor Fenton
Subject: Re: What about BC?

Hi David,

In this system, 1 AD is the year 1, 1 BC (or BCE) is the year 0, 
and 2 BC (BCE) is the year -1, etc.  For negative years, Meeus 
says to replace the term

   int(365.25*y)  

by

   int(365.25*y - .75) .

To test your implementation, May 29 in the year -584 should be 
JD 1507900.5 (Meeus actually uses May 28.63 to get JD 1507900.13 .)

If you have any questions, please write back and I will try to 
explain further.

- Doctor Fenton, The Math Forum
  http://mathforum.org/dr.math/ 
Associated Topics:
Middle School Calendars/Dates/Time

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/