note 54989 modified in function.checkdate by cece
| From: | cece@php.net | Date: | Tue, 15 Nov 2005 14:36:38 +0000 |
| Subject: | note 54989 modified in function.checkdate by cece | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98591@lists.php.net to get a copy of this message | ||
Here's a date validation snippet I wrote, since I wasn't able to find one that was
flexible enough. It accepts dates in m-d-y format (2- or 4-digit year) and both dashes and slashes
as separators.
$strDate = $yourDate;
$isValid = false;
if (ereg('^([0-9]{1,2})[-,/]([0-9]{1,2})[-,/](([0-9]{2})|([0-9]{4}))$', $strDate)) {
$dateArr = split('[-,/]', $param->value);
$m=$dateArr[0]; $d=$dateArr[1]; $y=$dateArr[2];
$isValid = checkdate($m, $d, $y);
}
if (!$isValid) {
// take appropriate action
}
// then, to obtain the timestamp
$date = mktime(null,null,null,$m,$d,$y);
--was--
Here's a date validation snippet I wrote, since I wasn't able to find one that was
flexible enough. It accepts dates in m-d-y format (2- or 4-digit year) and both dashes and slashes
as separators.
$strDate = $yourDate;
$isValid = false;
if (ereg('([0-9]{1,2})[-,/]([0-9]{1,2})[-,/](([0-9]{2})|([0-9]{4}))', $strDate)) {
$dateArr = split('[-,/]', $param->value);
$m=$dateArr[0]; $d=$dateArr[1]; $y=$dateArr[2];
$isValid = checkdate($m, $d, $y);
}
if (!$isValid) {
// take appropriate action
}
// then, to obtain the timestamp
$date = mktime(null,null,null,$m,$d,$y);
http://php.net/manual/en/function.checkdate.php