I would use something like:-
$date = '09/09/2005';
list($month, $day, $year) = explode("/", $date);
if(checkdate($month, $day, $year)) {
/* valid date */
} else {
/* invalid date */
}
Todd Cary wrote:
I need to check the input of a user to make sure the date is valid and
correctly formatted. Are there any examples available?
Here is one solution I created:
/* Is date good */
function is_date_good($date) {
if (strtotime($date) == -1) {
$retval = 0;
} else {
if (strpos($date, "/") > 0) {
$parts = explode("/", $date);
} elseif (strpos($date, "-") > 0) {
$parts2 = explode("-", $date);
$parts[0] = $parts2[1];
$parts[1] = $parts2[2];
$parts[2] = $parts2[0];
} else {
$parts = explode(".", $date);
}
//print_r($parts);
if (checkdate($parts[0], $parts[1], $parts[2]) )
return 1;
else
return 0;
}
return $retval;
}
Is there a simplier solution?
Many thanks......
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php