picture picture
November 1, 2011 PHP 0 Comments

Date format validation in PHP

Function to validate a date in “YYYY-MM-DD” format.

[code type=php]
function checkDateFormat($date)
{
//match the format of the date
if (preg_match (“/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/”, $date, $parts))
{
//check weather the date is valid of not
if(checkdate($parts[2],$parts[3],$parts[1]))
return true;
else
return false;
}
else
return false;
}
[/code]

Tags:

No Responses to “Date format validation in PHP”

Leave a Reply

Name

Mail (will not be published)

Website