note 62611 added to function.checkdate

From: Date: Sun, 05 Mar 2006 09:07:28 +0000
Subject: note 62611 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-104840@lists.php.net to get a copy of this message
Taking the comments of Hightechguy into account, here is a version with variable date formatting: <?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') { $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 ); } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 85.178.124.3 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- http://master.php.net/note/edit/62611 Del: integrated -- http://master.php.net/note/delete/62611/integrated Del: useless -- http://master.php.net/note/delete/62611/useless Del: bad code -- http://master.php.net/note/delete/62611/bad+code Del: spam -- http://master.php.net/note/delete/62611/spam Del: non-english -- http://master.php.net/note/delete/62611/non-english Del: in docs -- http://master.php.net/note/delete/62611/in+docs Del: other reasons-- http://master.php.net/note/delete/62611 Reject -- http://master.php.net/note/reject/62611 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104840) next »