note 54989 deleted from function.checkdate by bjori
| From: | bjori@php.net | Date: | Wed, 11 Oct 2006 08:26:17 +0000 |
| Subject: | note 54989 deleted from function.checkdate by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118394@lists.php.net to get a copy of this message | ||
Note Submitter: Matt Browne
----
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);