[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

Determining a leap year

Does anyone have a small snip of code that determines if a year is a leap year.

Or explain the rules that goven what determines if a year is a leap year.  

Thanks
0
rock1
Asked:
rock1
  • 3
  • 2
  • 2
1 Solution
 
SlartiCommented:
It's very simple: It's a leap year if the year number is divisible by 4. The exception is that if the year is divisible by 100, it is _not_ a leap year. The exception to that is that the year 2000 _will_ be a leap year (so will the year 3000 if you plan to live that long).

0
 
nietodCommented:
I'm 99% sure--addmitidly not 100% sure that you missed one.  If the year is divisible by 400 it is a leap year (even though it is divisble by 100.)  Then If it is divisible by 2000, it is not a leap year (even though it is divisible by 400).  

Can anyone confirm that?
0
 
rock1Author Commented:
I did some more research on this.

Every 4 years is a leap year (1992, 1996, ...).  But, as an exception,
every 100 years is not a leap year (2100, 2200, ...).  But as an exception
to this exception, every 400 years is a leap year (2000, 2400, ...).

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nietodCommented:
Well we got three opinions now.  None completely agree with the other.  But does it matter?  Over what time span does this matter?  Most likely the only exception year that will matter is the year 2000.  If so, the question then is, is it a leap year.
0
 
rock1Author Commented:
Yes, 2000 is a leap year.  Because it is divisible by 400.

Basically,

If the year is divisble by 4 it is a leap year.
But as an exception, every 100 years is not a leap year ( 2100, 2200 )
However, every 400 years is a leap year.  So 2000, 2400 are leap years.

Here is a code chunk I grabbed from someone.
bool bLeap = !( nYear % 4 ) && ( ( nYear % 100) || !( nYear % 400 ));

0
 
SlartiCommented:
This is probably true. I am not sure whether year 3000 is really a leap year. But, as nietod said, it doesn't really matter for any practical purpose.
0
 
rock1Author Commented:
3000 Would not be a multiple because even though it can be divided by 4 and a 100, it is not a multiple of 400.


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now