note 92447 added to function.date
| From: | seanj at osu1 dot php dot net | Date: | Fri, 24 Jul 2009 14:58:53 +0000 |
| Subject: | note 92447 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158692@lists.php.net to get a copy of this message | ||
An earlier user posted a script to detect whether or not a given year is a leap year:
<?php
function is_leapyear($year = 2004) {
$is_leap = date('L', strtotime("$year-1-1"));
return $is_leap;
}
?>
You're thinking too hard! Just check to see if the year is a multiple of four:
<?php
function is_leapyear($year = 2004) {
return ($year%4)==0;
}
?>
or better yet, just use that single line in your code.
----
Server IP: 64.71.164.2
Probable Submitter: 98.24.198.1
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/92447
Del: integrated -- https://master.php.net/note/delete/92447/integrated
Del: useless -- https://master.php.net/note/delete/92447/useless
Del: bad code -- https://master.php.net/note/delete/92447/bad+code
Del: spam -- https://master.php.net/note/delete/92447/spam
Del: non-english -- https://master.php.net/note/delete/92447/non-english
Del: in docs -- https://master.php.net/note/delete/92447/in+docs
Del: other reasons-- https://master.php.net/note/delete/92447
Reject -- https://master.php.net/note/reject/92447
Search -- https://master.php.net/manage/user-notes.php