# Check for a leap year in VB



## Aftab (Oct 15, 2003)

A quick way to check if a year is a leap year

public function IsLeap(Year as integer) as boolean
IsLeap = Isdate("29/02/" & Year)
end function


----------



## n2gun (Mar 3, 2000)

Another simple way is divide the year by 4. If it comes out without a remainder it is a leap year.


----------



## Aftab (Oct 15, 2003)

Its not as simple as just dividing the year by 4, the actual logic for a leap year is:
year is divisible by 4, but NOT by 100 OR year is divisible by 400.


----------



## n2gun (Mar 3, 2000)

> _Originally posted by Aftab:_
> *Its not as simple as just dividing the year by 4, the actual logic for a leap year is:
> year is divisible by 4, but NOT by 100 OR year is divisible by 400. *


DUH I don't see where I said anything about 100 or 400. *Could you show where I did ?*


----------



## Aftab (Oct 15, 2003)

> DUH I don't see where I said anything about 100 or 400. Could you show where I did ?


You have misunderstood what I said. I was pointing out the actual logic of calculating a leap year, I was not trying to say that you had said anything about dividing by 100 and 400. This is what I was trying to get across: A year is a leap year IF the year is divisible by 4 AND 100, OR is divisible by 400.


----------



## Aftab (Oct 15, 2003)

Sorry, slight error in last reply, logic is divisible by 4 but NOT divisible by 100 OR divisible by 400.


----------



## dannyboyfx (Nov 19, 2003)

why can't it be divisible by 100?


----------



## SIR****TMG (Aug 12, 2003)

ALL THIS GAVE ME A HEAD ACHE


----------



## Aftab (Oct 15, 2003)

> why can't it be divisible by 100?


The reason it can't be divisible by 100 is because then we would have a leap year every 100 years (century years) as well as every 4 years. This would result in too many extra days being added, about 3 days every 400 years I think. Hope this makes sense.


----------



## dannyboyfx (Nov 19, 2003)

i think so.


----------



## Big-K (Nov 22, 2003)

They explained all of that in an article in the Kansas City Star a few weeks ago. Pretty weird stuff it is.


----------



## Alfie_UK (Mar 28, 2003)

> _Originally posted by SIR****TMG:_
> * ALL THIS GAVE ME A HEAD ACHE *


 Same here,just took couple of paracetamols


----------



## -Sx- (Mar 28, 2004)

I suppose no one *really* uses the Internet anymore 

How about this site:
http://www.codetoad.com/vb_leap_year.asp

Any year divisible by 400 will be divisible by 100 as well as 4. The operative function is If divisible by 4 cannot be divisible by 100 - so 2004 is a Leap Year.
2000 is a special case because it was divisble by all three...

( BTW - we do have leap years *every* 100 years


----------



## -Sx- (Mar 28, 2004)

Grrr ... I take that last part back - we are entering aperiod where leaps years at the century mark are occuring less often:

$year = 100;
while(1) {
system("cal 2 $year");
sleep 1;
$year+=100;
}

Prior to 1800 every century was a leap year...

Sorry/Bill


----------



## Aftab (Oct 15, 2003)

Sorry if I didn't make that clear:
A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.


----------

