note 87572 added to function.checkdate
| From: | parris dot varney at gmail dot com | Date: | Thu, 11 Dec 2008 03:24:41 +0000 |
| Subject: | note 87572 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148015@lists.php.net to get a copy of this message | ||
I put together an is_date function using checkdate. Works the same as is_numeric.
public static function is_date($date)
{
$date = str_replace(array('\'', '-', '.', ','),
'/', $date);
$date = explode('/', $date);
if( count($date) == 1 // No tokens
and is_numeric($date[0])
and $date[0] < 20991231 and
( checkdate(substr($date[0], 4, 2)
, substr($date[0], 6, 2)
, substr($date[0], 0, 4)))
)
{
return true;
}
if( count($date) == 3
and is_numeric($date[0])
and is_numeric($date[1])
and is_numeric($date[2]) and
( checkdate($date[0], $date[1], $date[2]) //mmddyyyy
or checkdate($date[1], $date[0], $date[2]) //ddmmyyyy
or checkdate($date[1], $date[2], $date[0])) //yyyymmdd
)
{
return true;
}
return false;
}
----
Server IP: 208.69.120.35
Probable Submitter: 173.48.34.127
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- https://master.php.net/note/edit/87572
Del: integrated -- https://master.php.net/note/delete/87572/integrated
Del: useless -- https://master.php.net/note/delete/87572/useless
Del: bad code -- https://master.php.net/note/delete/87572/bad+code
Del: spam -- https://master.php.net/note/delete/87572/spam
Del: non-english -- https://master.php.net/note/delete/87572/non-english
Del: in docs -- https://master.php.net/note/delete/87572/in+docs
Del: other reasons-- https://master.php.net/note/delete/87572
Reject -- https://master.php.net/note/reject/87572
Search -- https://master.php.net/manage/user-notes.php