LEAP YEAR CALCULATION

1. Member
Join Date
Dec 1969
Posts
94

## LEAP YEAR CALCULATION

I need the leap year calculation........

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Which one of dozens?

What do you want to do that the builtin VBS functions don&#039t already do for you?<BR><BR>Or do you simply want to know if a given year *is* a leap year?<BR><BR>Even then, there are several ways to do it.<BR><BR>&#060;%<BR>yr = 2000 &#039 or 1999 or 2001 or or or<BR>leap = False<BR>If (yr MOD 4) = 0 Then<BR>&nbsp; &nbsp; leap = True<BR>&nbsp; &nbsp; If (yr MOD 100) = 0 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; leap = False<BR>&nbsp; &nbsp; &nbsp; &nbsp; If (yr Mod 400) = 0 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; leap = True<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; End If<BR>End If<BR>%&#062;<BR><BR>but you could get sneaky and use some VBS functions:<BR><BR>&#060;%<BR>yr = 2000 &#039 or 1999 or 2001 or or or<BR>leap = ( Month( DateSerial(yr,2,29) ) = 2 )<BR>%&#062;<BR><BR>How that works: DateSerial will construct the date "Feb 29, YYYY" (where YYYY is the value in the yr variable). BUT...<BR><BR>If you ask for Feb 29 in a year that is not a leap year, DateSerial is smart enough to convert it to March 1, instead!<BR><BR>So then we ask "what Month( is that )?" and test it against 2 (Feb). If, indeed, the month is still February, then the comparison returns true...this is a leap year.<BR><BR>Sneaky?<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
487

## Bit of a guess ......

I&#039m not really sure, but I think that it&#039s something like:<BR><BR>&#060;HTML&#062;<BR>&#060;HEAD&#062;< BR>&#060;TITLE&#062;The isLeap Year function.&#060;/TITLE&#062;<BR>&#060;/HEAD&#062;<BR>&#060;BODY&#062;<BR><BR>&#060;%<BR>F unction isLeap(year)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;If ((year Mod 4) = 0) And ((year Mod 100) &#060;&#062; 0) Or ((year Mod 400) = 0) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;isLeap = " is "<BR>&nbsp;&nbsp;&nbsp;&nbsp;Else<BR>&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isLeap = " is not "<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR><BR>End Function<BR><BR>For i = 1 to 400<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "The Year " & i & isLeap(i) & "a leap year.<BR>"<BR><BR>Next<BR>%&#062;<BR><BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR><BR>HTH<BR>Darren<BR>darren@showusyo urcode.com

4. Senior Member
Join Date
Dec 1969
Posts
487

## Yes

That was sneaky &#060;he he&#062;

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## So another sneaky:

I purposely used nested IFs to show the logic of the thing, but if you are going to do it the "quicky" way, then why not:<BR><BR>&#060;%<BR>Function isLeap(year)<BR>&nbsp; &nbsp; isLeap = ( ((year Mod 4) = 0) And ((year Mod 100) &#060;&#062; 0) ) Or ((year Mod 400) = 0)<BR>End Function<BR>%&#062;<BR><BR>And just have it return True/False, thus.<BR><BR>(Yeah, I know, the extra parens I put in there aren&#039t needed if you pay attention to precedence of operators. But I&#039m paranoid.)<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•