View Full Version : different date format validations ??

07-15-2008, 11:47 AM
hello forums!!
can anybody give idea on different types of date format validation function like Y-m-d , dmY etc.

function validateDate($input_date, $format){
//necessary processings....
return bool;
validateDate('2008-08-135', 'Y-m-d');

Thanks in advance for the valueable suggestions

07-15-2008, 03:58 PM
Really, all you should need to do is break up the full date into parts (month, day, and year) and then use the checkdate() function that is built into PHP.

FYI, to break up a full date, just use explode() with a delimiter of "-" or whatever is separating your date. explode() will send the date into an array with each value being a portion of your date. For instance:

$full_date = '2008-07-15';

$date_array = explode('-', $full_date);

$year = $date_array[0];
$month = $date_array[1];
$day = $date_array[2];

if (checkdate($month, $day, $year)) {
//continue with script

Does that help?