note 54948 added to function.checkdate

From: Date: Wed, 20 Jul 2005 13:31:31 +0000
Subject: note 54948 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-92214@lists.php.net to get a copy of this message
If you need to check a MySQL format date, here's a function to do it: /* * Check a MySQL (ISO 8601 based) format date * * The first part splits the date up into its component parts, checking that * they appear to be roughly OK. The regex specifically looks for: * four digits between 1000 and 9999, -, two digits between 01 and 12, -, * two digits between 01 and 31). * * The second part makes sure that the date is definitely valid (taking into * account leap years). * * See http://dev.mysql.com/doc/mysql/en/datetime.html for details on the MySQL * date format. */ function checkmysqldate($isodate) { if (preg_match("/^([123456789][[:digit:]]{3})-(0[1-9]|1[012])- (0[1-9]|[12][[:digit:]]|3[01])$/", $isodate, $date_part) && checkdate($date_part[2], $date_part[3], $date_part[1])) { return true; } else { return false; } } (The form made me insert a character return between the hyphen and open bracket in the regex line due to wrapping. Just join those two lines together to get the code to work!) ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54948 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54948&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54948&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54948&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54948&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54948&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54948&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54948&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92214) next »