note 85321 added to function.checkdate
| From: | saturn at ax dot com dot tw | Date: | Tue, 26 Aug 2008 06:06:01 +0000 |
| Subject: | note 85321 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143820@lists.php.net to get a copy of this message | ||
I wrote a simple function to converter datetime to UNIX timestamp. If the input time with error
format, the function will return current timestamp.
function datetime2timestamp($datetime)
{
$datetime = str_replace('-', ' ', $datetime);
$datetime = str_replace('/', ' ', $datetime);
$datetime = str_replace(':', ' ', $datetime);
$array = explode(' ', $datetime);
$year = $array[0];
$month = $array[1];
$day = $array[2];
$array[3] ? $hour = $array[3] : $hour = '00';
$array[4] ? $minute = $array[4] : $minute = '00';
$array[5] ? $second = $array[5] : $second = '00';
if (preg_match("/^(\d{4}) (\d{2}) (\d{2}) ([01][0-9]|2[0-3]) ([0-5][0-9])
([0-5][0-9])$/", "$year $month $day $hour $minute $second", $matches)) {
if (checkdate($matches[2], $matches[3], $matches[1])) {
return mktime(intval($hour), intval($minute), intval($second), intval($month), intval($day),
intval($year));
} else {
return time();
}
} else {
return time();
}
}
----
Server IP: 140.113.54.119
Probable Submitter: 60.199.247.200
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- https://master.php.net/note/edit/85321
Del: integrated -- https://master.php.net/note/delete/85321/integrated
Del: useless -- https://master.php.net/note/delete/85321/useless
Del: bad code -- https://master.php.net/note/delete/85321/bad+code
Del: spam -- https://master.php.net/note/delete/85321/spam
Del: non-english -- https://master.php.net/note/delete/85321/non-english
Del: in docs -- https://master.php.net/note/delete/85321/in+docs
Del: other reasons-- https://master.php.net/note/delete/85321
Reject -- https://master.php.net/note/reject/85321
Search -- https://master.php.net/manage/user-notes.php