validate date - problem php
i am trying this code to validate a date but i get false. what is the reason of that?
function validate_age($form) {
$str =开发者_如何学JAVA "1977/03/27";
$stamp = strtotime( $str );
if (!is_numeric($stamp)) {
echo ("nop");
return FALSE;
}
$year = date( 'Y', $stamp );
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
if (checkdate($year, $month, $day)){
return TRUE;
}
return FALSE; //stops here
}
validate_age($form);
thanks
Check the order of your arguments
checkdate($month, $day, $year);
It's all wrote in the php official docu: http://it.php.net/checkdate
month supposed to be from 1 to 12 (no zeros in front)
checkdate($month, $day, $year);
as in checkdate(3, 27, 1977);
not checkdate(03, 27, 1977);
so for month you should use $month = date( 'n', $stamp );
精彩评论