note 87572 modified in function.checkdate by danbrown
| From: | danbrown@php.net | Date: | Thu, 11 Dec 2008 03:27:35 +0000 |
| Subject: | note 87572 modified in function.checkdate by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148016@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.
<?php
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;
}
?>
--was--
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;
}
http://php.net/manual/en/function.checkdate.php