note 92518 added to function.date
| From: | a dot rajcany at NOSPAM dot mac dot com | Date: | Tue, 28 Jul 2009 05:24:37 +0000 |
| Subject: | note 92518 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158808@lists.php.net to get a copy of this message | ||
Reply to "seanj" below:
Sorry, your code for determining a leap year is wrong. You cannot just do a mod 4 to determine a
leap year.
"Years that are evenly divisible by 100 are not leap years, unless they are also evenly
divisible by 400, in which case they are leap years. For example, 1600 and 2000 were leap years, but
1700, 1800 and 1900 were not." quote from Wikipedia http://en.wikipedia.org/wiki/Leap_year
The function "sarmad dot saadi at gmail dot com" wrote is correct and yours in wrong.
Alternatively you can you use the function below
<?php
function isLeapYear($year){
if( (($year%4 === 0) && ($year%100 !== 0)) || ($year%400 === 0) ){
return true;
}
else{
return false;
}
}
var_dump( isLeapYear(2000) ); //true
var_dump( isLeapYear(2004) ); //true
var_dump( isLeapYear(2100) ); //false
var_dump( isLeapYear(1700) ); //false
var_dump( isLeapYear(1800) ); //false
var_dump( isLeapYear(1900) ); //false
?>
----
Server IP: 117.104.162.229
Probable Submitter: 137.154.73.31 (proxied: 137.154.73.31)
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/92518
Del: integrated -- https://master.php.net/note/delete/92518/integrated
Del: useless -- https://master.php.net/note/delete/92518/useless
Del: bad code -- https://master.php.net/note/delete/92518/bad+code
Del: spam -- https://master.php.net/note/delete/92518/spam
Del: non-english -- https://master.php.net/note/delete/92518/non-english
Del: in docs -- https://master.php.net/note/delete/92518/in+docs
Del: other reasons-- https://master.php.net/note/delete/92518
Reject -- https://master.php.net/note/reject/92518
Search -- https://master.php.net/manage/user-notes.php