Julian dates


Thread Starter

Matt Myers

Anyone have a good algorithm for calculating Julian Dates??

Thanks in Advance!

Matt Myers
Electrical Engineer
S2F Engineering

This is from a really old HP book which I used for writing programs back in
the seventies. Note that it's Y2K compliant, but not Y2.1K compliant.

March 1 1700 is day 1. But do not use for days previous to February 18,
1900 or for days after February 28, 2100.

N(M,D,Y) = int(365.25 g(y,m)) + int(30.6 f(m)) + D - 621049

where g(y,m) = y-1 if m=1 or 2, or y if m>2
f(m) = m+13 if m= 1 or 2, or m+1 if m>2

You'll have to do a subtract for the reference date.


Willy Smith
Numatico SA

Robert Nickel

The best (read fastest) way I know of to do this is make an unsigned int array with the list of values for leap year and non-leap year items:
unsigned int Jdays[] =
unsigned int JdaysL[] =

then call it in your code as:

unsigned int jday;
if (jday % 4 == 0) {
jday = JdaysL[month-1] + dayinmonth;
}else {
jday = Jdays[month-1] + dayinmonth;


Anthony Kerstens

I found this while surfing. I don’t know who authored it, but maybe it’s what you’re looking for.
Anthony Kerstens P.Eng.

Leap Year Rules for Centuries!!
One Solar Year is Approximately Equal to 365.24219878 Days (Give or Take)
The Egyptians called it 365 and left it at that. But their calendar got out of step with the seasons, so that after around 750 years of this they were celebrating The Fourth of July in the middle of the winter. But consider the benefits: here in Boston, Massachusetts, there was all that extra room for picnics and blankets at the Esplanade on the frozen Charles River! The Romans wised up and added the leap day every four years to get the 365.25 day Julian year. Much better, but notice that this time the year is longer than it ought to be. The small difference between this and the true length of the year caused the seasons to creep through the calendar once again, only slower and in the other direction. After only 2300 years of this, July Fourth would once again fall in mid-winter. Fortunately things never reached that sad state. By 1582 the calendar was about ten days out of whack, so Pope Gregory XIII included the correction that’s still in use today.
If the year is divisible by 100, it’s not a leap year UNLESS it is also divisible by 400.
More recently, proposals for fixes have gotten even better than that. One suggested change is to add on “if the year is also divisible by 4000, it’s not a leap year.”
Here’s what it looks like:
Formula: 365
Year length: 365
Error: 0.24219878
Years to get 6 months out of whack: 754

Formula: 365 + ¼
Year length: 365.25
Error: 0.0078122
Years to get 6 months out of whack: 23,377

Formula: 365 + ¼ - 1/100 + 1/400
Year length: 365.2425
Error: 0.00030122
Years to get 6 months out of whack: 606,272

Formula: 365 + ¼ - 1/100 + 1/400 - 1/4000
Year length: 365.24225
Error: 0.00005122
Years to get 6 months out of whack: 3,565,426

Michael Strong

Looks like this would work in 2000, which is a leap year, but not in 2100, 2200, 2300, which are not leap years. Need to test if it is a century, whether it is divisible by 400.

Michael Strong—Fayetteville, NC
Email: [email protected]
Reply to an old posting: Sorry to be late, but better than never. :)

I'd like to recommend a book called "Calendrical calculations" if you are
looking for very detailed descriptions of various calendars and
calendar-related formulae.
This book was very helpful in my case.

At this URL, you can find links to some other calendar-related books as well.

Home page of the authors for this edition of the book:
They have a Java calendar applet there.
Looks impressive.
Also, there is a very detailed list of URL links to calendar-related sites.
You might find some free codes there if you have some free time to look
(There is a section for (calendar) conversion programs.)

By the way, they just printed a second edition of the book a couple months

Hope it helps.

Thread starter Similar threads Forum Replies Date
T Distributed Control Systems - DCS 0
G Languages 7