note 63335 deleted from function.checkdate by bjori

From: Date: Wed, 11 Oct 2006 08:26:26 +0000
Subject: note 63335 deleted from function.checkdate by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118395@lists.php.net to get a copy of this message
Note Submitter: moklet ---- ANd now it accepts date formats like yyyy/mm/dd as well <?php /** * Checks for a valid date * * @param string Date in the format given by the format parameter. * @param integer Disallow years more than $yearepsilon from now (in future as well as in past) * @param string Formatting string. Has to be one of 'dmy', 'dym', 'mdy', 'myd', 'ydm' or 'ymd'. (Default is 'ymd' for ISO 8601 compability) * @return array [ year, month, day ] * @since 1.0 */ function datecheck($date, $yearepsilon=5000, $format='ymd') { $date=str_replace("/", "-", $date); $format = strtolower($format); if (count($datebits=explode('-',$date))!=3) return false; $year = intval($datebits[strpos($format, 'y')]); $month = intval($datebits[strpos($format, 'm')]); $day = intval($datebits[strpos($format, 'd')]); if ((abs($year-date('Y'))>$yearepsilon) || // year outside given range ($month<1) || ($month>12) || ($day<1) || (($month==2) && ($day>28+(!($year%4))-(!($year%100))+(!($year%400)))) || ($day>30+(($month>7)^($month&1)))) return false; // date out of range return array( 'year' => $year, 'month' => $month, 'day' => $day ); } ?>

« previous php.notes (#118395) next »