note 92533 deleted from function.date by peehaa

From: Date: Sun, 28 Apr 2019 10:20:41 +0000
Subject: note 92533 deleted from function.date by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210764@lists.php.net to get a copy of this message
Note Submitter: Just.Kevin ---- In order to determine if a year is a leap year an earlier poster suggested simply checking to see if the year is a multiple of four: <?php function is_leapyear_broken($year = 2004) { return ($year%4)==0; } ?> While this will work for the majority of years it will not work on years that are multiples of 100 but not multiples of 400 i.e.(2100). A function not using php's date() function that will also account for this small anomaly in leap years: <?php function is_leapyear_working($year = 2004) { if((($year%4==0) && ($year%100!=0)) || $year%400==0) { return true; } return false; } ?> While is_leapyear_working will not return true for the few non-leap years divisible by four I couldn't tell you if this is more or less efficient than using php's date() as an even earlier poster suggested: <?php function is_leapyear($year = 2004) { $is_leap = date('L', strtotime("$year-1-1")); return $is_leap; } ?>

« previous php.notes (#210764) next »