note 61348 added to function.checkdate

From: Date: Wed, 01 Feb 2006 10:17:01 +0000
Subject: note 61348 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-102803@lists.php.net to get a copy of this message
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 ); } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 207.232.39.2 ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61348 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61348&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61348&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102803) next »