note 60291 deleted from function.preg-match by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:28:06 +0000 |
| Subject: | note 60291 deleted from function.preg-match by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127616@lists.php.net to get a copy of this message | ||
Note Submitter: Zientar
----
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";
}
?>