note 92518 deleted from function.date by danbrown

From: Date: Tue, 28 Jul 2009 14:21:18 +0000
Subject: note 92518 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158825@lists.php.net to get a copy of this message
Note Submitter: a dot rajcany at NOSPAM dot mac dot com ---- 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 ?>

« previous php.notes (#158825) next »