Click to See Complete Forum and Search --> : isDate isTime


kproc
03-02-2007, 05:43 PM
Hi is there a function that will test if a value is a date or a time value in php

NightShift58
03-02-2007, 05:57 PM
The closest you get is by using strtotime().

If the function returns anything besides a "-1" (or false, starting with PHP 5.1.0), then you've got a valid date/time... It's a bit iffy, I know...<?php
IF (strtotime($str) !== FALSE AND strtotime($str) <> -1) :
// Possibly a valid date/time
ELSE :
// Definitely not a valid date/time
ENDIF;
?>

NogDog
03-02-2007, 06:50 PM
If you have the numeric values for year, month, and day (either explicitly or else parsed from the input value), you can use the checkdate() function (htp://www.php.net/checkdate) to verify that it's a legitimate date.