tags:

views:

35

answers:

1

Can this format 10-7-2010 validated with php? With this script:

$array = explode('-', $str);
$day = $array[0];
$month = $array[1];
$year = $array[2];
$Valid = checkdate($month, $day, $year);

I have this error:

checkdate() expects parameter 2 to be long

How can I validate such format? Thanks in advance

+2  A: 

try changing to: $Valid = checkdate((int)$month, (int)$day, (int)$year);

edit: I tried your code and it works fine, could it be you have an poorly formatted date somewhere you're trying to pass in?

edit2: 10-7-2007 is a valid date, but it sounds like you think it should not be? It is a date in the past, so if you are trying to determine if a date is in the future, you could do something like this:

$isValid = ( strtotime("$year-$month-$day") > time() );

Rob
There's no reason he should have to. This will only hide bugs.
Artefacto
@Rob, Thanks, Now there is not any error. But yet the 10-7-2007 is valid :(
phpExe
yes, because 10-7-2007 is a valid date...
Rob
May there is a space or hidden char at this end of the string
M42
@M42 If there were, it would be discarded by the conversion to number when the string was passed to checkdate.
Artefacto