
LEAP YEAR CALCULATION
I need the leap year calculation........

Which one of dozens?
What do you want to do that the builtin VBS functions don't 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><%<BR>yr = 2000 ' or 1999 or 2001 or or or<BR>leap = False<BR>If (yr MOD 4) = 0 Then<BR> leap = True<BR> If (yr MOD 100) = 0 Then<BR> leap = False<BR> If (yr Mod 400) = 0 Then<BR> leap = True<BR> End If<BR> End If<BR>End If<BR>%><BR><BR>but you could get sneaky and use some VBS functions:<BR><BR><%<BR>yr = 2000 ' or 1999 or 2001 or or or<BR>leap = ( Month( DateSerial(yr,2,29) ) = 2 )<BR>%><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>

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

Yes
That was sneaky <he he>

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><%<BR>Function isLeap(year)<BR> isLeap = ( ((year Mod 4) = 0) And ((year Mod 100) <> 0) ) Or ((year Mod 400) = 0)<BR>End Function<BR>%><BR><BR>And just have it return True/False, thus.<BR><BR>(Yeah, I know, the extra parens I put in there aren't needed if you pay attention to precedence of operators. But I'm 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

Forum Rules

