PHP - How to check whether a year is bisect (i.e. a leap year)?
A bisect year is another name for a leap year. Use the L
formatter, where $year
is the year you are testing:
echo (date('L', strtotime("$year-01-01")) ? 'Yes' : 'No');
To adjust the discordance between the calendar and seasons, the Julian calendar used the calculations of the Greek astronomer Sosigene and was based on the adoption of a 365.25 days year: 3 years of 365 days followed by a 366 days year, the supplementary day being added always after the 24th of February (sexto ante calendas Martiis = the sixth day before the March calends) being called bis sexto (the sixth day bis), hence the names of bisect year and bisect day for the leap day. The year was divided in 12 months, which alternated 31 and 30 days and February had, in normal years, 29 days and 30 days in bisect years.
Later, when the eighth month was dedicated to the emperor Augustus (August), this month was made of 31 days to match July, the month dedicated to Julius Caesar. That's why February was made of 28 days, having 29 days in bisect years.
http://news.softpedia.com/news/The-History-of-Modern-Calendar-and-Bisect-Year-79892.shtml
You can use PHP's date() function to do this...
// L will return 1 if it is a leap year, 0 otherwise
echo date('L');
// use your own timestamp
echo date('L', strtotime('last year'));
// for specific year
$year = 1999;
$leap = date('L', mktime(0, 0, 0, 1, 1, $year));
echo $year . ' ' . ($leap ? 'is' : 'is not') . ' a leap year.';
Let me know if this does this trick for you, Cheers!
UPDATE: Added Example for Specific Year
function is_leap_year($year)
{
return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));
}