note 92533 added to function.date

From: Date: Tue, 28 Jul 2009 16:52:49 +0000
Subject: note 92533 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-158832@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 24.111.3.150 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/92533 Del: integrated -- https://master.php.net/note/delete/92533/integrated Del: useless -- https://master.php.net/note/delete/92533/useless Del: bad code -- https://master.php.net/note/delete/92533/bad+code Del: spam -- https://master.php.net/note/delete/92533/spam Del: non-english -- https://master.php.net/note/delete/92533/non-english Del: in docs -- https://master.php.net/note/delete/92533/in+docs Del: other reasons-- https://master.php.net/note/delete/92533 Reject -- https://master.php.net/note/reject/92533 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158832) next »