note 60291 added to function.preg-match

From: Date: Mon, 02 Jan 2006 15:54:20 +0000
Subject: note 60291 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-101110@lists.php.net to get a copy of this message
With this function you can check your date and time in this format: "YYYY-MM-DD HH:MM:SS" <?php function Check_Date_Time($date_time) { if (preg_match("/^([123456789][[:digit:]]{3})- (0[1-9]|1[012])-(0[1-9]|[12][[:digit:]]|3[01]) (0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $date_time, $part) && checkdate($part[2], $part[3], $part[1])) { return true; } else { return false; } } $my_date_time = "2006-01-02 16:50:15"; if (Check_Date_Time($my_date_time)) { echo "My date '".$my_date_time."' is correct"; } else { echo "My date '".$my_date_time."' is incorrect"; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60291 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60291&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60291&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101110) next »