note 54948 deleted from function.checkdate by bjori

From: Date: Wed, 11 Oct 2006 08:25:57 +0000
Subject: note 54948 deleted from function.checkdate by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118393@lists.php.net to get a copy of this message
Note Submitter: Zoe Blade ---- 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!)

« previous php.notes (#118393) next »