Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

leap year function

Status
Not open for further replies.

tziviak

Technical User
Oct 10, 2002
128
0
0
US
is there a way to check if a certain date-is a leap year?
 
There is a lot of stuff on the web, and the general rule is:

if (year mod 4 <> 0)
{use 28 for days in February}
else if (year mod 400 = 0)
{use 29 for days in February}
else if (year mod 100 = 0)
{use 28 for days in February}
else
{use 29 for days in February}

However, I saw another solution on that is incredibly simple, using the built-in VBA functions (although web example in PowerBuilder):

IsLeapYear = IsDate(&quot;29 Feb yyyy&quot;)

Substitute your year for the 'yyyy'.
e.g. IsDate(&quot;29 Feb 2000&quot;) is True, IsDate(&quot;29 Feb 2002&quot;) is False.
 
Just for the fun of it:

Code:
MyDate = Date
IsLpYr2 = IsDate(&quot;2/29/&quot; & Year(MyDate))
IsLpYr3 = DateDiff(&quot;d&quot;, &quot;1/1/&quot; & Year(MyDate), &quot;1/1/&quot; & Year(MyDate) + 1) = 366
? IsLpYr, IsLpYr2, IsLpYr3
False         False         False



strMyDate = &quot;3/13/96&quot;
IsLpYr4 = IsDate(&quot;2/29/&quot; & Year(strMyDate))
IsLpYr5 = IsDate(&quot;2/29/&quot; & Year(strMyDate))
IsLpYr6 = DateDiff(&quot;d&quot;, &quot;1/1/&quot; & Year(strMyDate), &quot;1/1/&quot; & Year(strMyDate) + 1) = 366
? IsLpYr4, IsLpYr5, IsLpYr6
True          True          True
[code]




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top