Julian Date Formula
I finally found the formula to calculate the julian date. Here it is. Thanks for the replies. I tried using the "Date" data type but it always has 1/1/1990 as a date. I'll have to read up on how to use that.
Mike
Find out the number of total days
days in year = 31 for JAN + 14 in FEB = 45
No. complete years * 365 = 1994 * 365 = 727810
19 centuries * 24 leap years/century = 456
1 leap year every 400 years = 19/4 = 4
leap years in current century = 94/4 = 23
Total days = 728 338
We can write a general formula as
Days = days in YY + (CCYY-1)*365 + CC*24 + TRUNC [CC/4] + TRUNC [(YY-1)/4]
where TRUNC[ ] truncates the integer divide to its lowest integral value; CC = 19; YY = 95
Next we need a method to convert total days into a calendar date.
Every 400 year interval has a constant number of days
days = 400*365 + 4*24 + 1 = 146,097 days
Within a 400 year interval every 100 year interval contains
days = 100*365 + 24 = 36,524 days
Within a 100 year interval every 4 years contains
days = 4*365 + 1 = 1,461 days
Finally within a 4 year interval each year contains 365 days.
With this information we can determine a calendar date by successively dividing out the intervals and multiplying as
Number of 400 year intervals
728,338/146,097 = 4, remainder = 143,950
4 * 400 = 1600
Number of 100 year intervals
143,950/36,524 = 3, remainder = 34,378
3 * 100 = 300
Number of 4 year intervals
34,378/1,461 = 23, remainder = 775
23 * 4 = 92
Number of 365 day years
775/365 = 2, remainder = 45
2
Accumulated years
1994
We have 1994 years plus 45 days into 1995
CCYY = 1994 + 1
MM = February
DD = 45 - 31(JAN) = 14
The calendar date is February 14, 1995.
The formula for the algorithm becomes
CCYY = TRUNC [DAYS/146,097] * 400 + TRUNC [remainder/36,524] * 100 + TRUNC [remainder/1,461] * 4 + TRUNC [remainder/365] + remainder
where the final remainder is the day number of the following year which is converted to a month and day.