note 61348 deleted from function.checkdate by nlopess

From: Date: Wed, 26 Jul 2006 12:51:41 +0000
Subject: note 61348 deleted from function.checkdate by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-115211@lists.php.net to get a copy of this message
Note Submitter: Hightechguy ---- As an addition to the function contributed by </Life>.org: You may want to use different date format "YYYY-MM-DD" like "2006-02-01", because a) it's default for mySQL and b) relatively easily retrieved from MSSQL if you use CONVERT function with style=ODBC canonical, which gives yyyy-mm-dd hh:mi:ss(24h) style Finally function looks like: <?php function dateCheck($date, $yearepsilon=5000) { // inputs format is "YYYY-MM-DD" ONLY ! if (count($datebits=explode('-',$date))!=3) return false; $year = intval($datebits[0]); $month = intval($datebits[1]); $day = intval($datebits[2]); 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 checkdate($month,$day,$year ); } ?>

« previous php.notes (#115211) next »