Leap Year Check

Description: Checks if the supplied year is a leap year.
Tested Platform: PHP 5
Language: PHP
// The year is a leap year if it is divisible by 4 (evenly) and is either 
// divisible by 400 (again evenly) or not by 100. 1900 was not a leap year, but 
// 2000 was because it was divisible by 400 even though it was.

function isLeapYear($year) {
     return ((($year % 4) == 0) && ((($year % 400) == 0) || (($year % 100) != 0)));
}

Submitted: December 11, 2012

Return to the snippets listing