Click here to Skip to main content
13,550,803 members
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 20 Feb 2000
Licenced CPOL

Leap Years

, , 20 Feb 2000
Rate this:
Please Sign up or sign in to vote.
A discussion on the thorny issue of leap years.

There has been a lot of interest about the correct method of calculating leap years lately, especially since it seems many programmers have got it wrong. Before Y2K the approximation "a leap year occurs every four years" was good enough for most situations. If you needed to deal with historical dates (post 1600AD), then you had to add the clause "unless the year was divisible by 100".

This is where many programmers left it - but the rule for the Gregorian calendar is:

  1. Most years divisible by 4 are Leap Years (i.e. 1996 was)
  2. However, most years divisible by 100 are NOT! (1900 was not)
  3. Unless they are also divisible by 400 (2000 will be)

It turns out though that there are even more subclauses that can be appended to these rules to take into account the fact that the Earth takes 365.2421898 days to orbit the sun (well, it did in 1996 - it's now a shade shorter than that). Because of this, the Gregorian calendar will be off by about a day in 3000 years or so. There are various proposals on how to deal with this, but it seems it won't really be an issue until 2800AD.

One proposal (by the astronomer John Herschel (1792-1871) among others) suggests

  • Every year which is divisible by 4000 is not a leap year.

This is more accurate than the Gregorian calendar, but has not been officially adopted.

Another proposal (by the Orthodox church in Greece) is to replace the "divisible by 400" rule by the following:

  • Every year which when divided by 900 leaves a remainder of 200 or 600 is a leap year.

This makes 1900, 2100, 2200, 2300, 2500, 2600, 2700, 2800 non-leap years, whereas 2000, 2400, and 2900 are leap years. This will not create a conflict with the rest of the world until the year 2800. However, this rule has also not been officially adopted.

Further reading:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Authors

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

LeRoy Baxter
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
CIDev24-Sep-10 6:18
memberCIDev24-Sep-10 6:18 
GeneralOrthodox Church Pin
m00n120-Jul-10 3:51
memberm00n120-Jul-10 3:51 
Questionhow about this Pin
simon.cropp9-Jul-07 18:39
membersimon.cropp9-Jul-07 18:39 
AnswerRe: how about this Pin
scottctr13-Jul-07 9:01
memberscottctr13-Jul-07 9:01 
AnswerRe: how about this Pin
Chris Maunder13-Jul-07 9:02
adminChris Maunder13-Jul-07 9:02 
GeneralOops! Pin
Chris Hills2-May-05 6:39
memberChris Hills2-May-05 6:39 
GeneralRe: Oops! Pin
Chris Maunder10-Jul-07 2:48
adminChris Maunder10-Jul-07 2:48 
QuestionHas anyone seen gmttime() ? Pin
Bamaco229-Jan-04 8:10
memberBamaco229-Jan-04 8:10 other words Pin
dixi16-Jul-00 12:04
sussdixi16-Jul-00 12:04 
GeneralRe: other words Pin
wulph10-Dec-03 13:56
memberwulph10-Dec-03 13:56 
GeneralHistory Pin
Michael Krebs25-Feb-00 12:45
sussMichael Krebs25-Feb-00 12:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180515.1 | Last Updated 21 Feb 2000
Article Copyright 2000 by Chris Maunder, LeRoy Baxter
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid