DeutschEnglish

Untermenü

 - - - By CrazyStat - - -
Last modified:
03.10.2023 - 16:42:36

Check whether a year is a leap year

The following function checks whether a given year is a leap year.


<?php
function is_leap_year($year) {
 return 
$year%4==&& ($year%100!=|| $year%400==0);
}
?>

Explanation

Per definition, a year is leap year if it can be divided by 4, but not by 100 except it can be divided by 400.
In short: Every 4 years, except centuries, but every 4th century.
So the year 2000 was a leap year for example, because it can be divided by 4, (100) and 400.