This year (2008) is a leap year, and this past week contained February 29. It seems only fitting that we talk about calculating leap years and what we can do with that information.
A leap year is always divisible by four, but not by one hundred unless it is also divisible by four hundred.
if someYear Mod 4 = 0 and (someYear Mod 100 <> 0 or (someYear Mod 100 = 0 and someYear Mod 400 = 0)) then
isLeapYear = True
isLeapYear = False
return date("L", strtotime($someYear . "-01-01"));
Now let's write a function to build on this which returns the number of days in a given month.
function MonthDays(someMonth, someYear)
select case someMonth
case 1, 3, 5, 7, 8, 10, 12
MonthDays = 31
case 4, 6, 9, 11
MonthDays = 30
if isLeapYear(someYear) then
MonthDays = 29
MonthDays = 28
function MonthDays($someMonth, $someYear)
return date("t", strtotime($someYear . "-" . $someMonth . "-01"));
UPDATE: Thanks to Jim Mayes for showing me more elegant PHP solutions.