Sunday, October 19, 2008

How to validate a date to see if its a correct date format using php

You have function called checkdate() where you can validate a input date is actually a correct date format. checkdate() will validate Gregorian date, so we need to properly give the parameters for the checkdate() function.
checkdate($month, $day, $year) - will return true or false


<?php

//checkdate($month, $day, $year) - format

$month = 10;
$day = 12;
$year = 2008;

echo 'Valid Date Example: ';

if(checkdate($month, $day, $year))
{
echo 'Date is correct';
}
else
{
echo 'Date is incorrect';
}

echo '<br /><br />';
echo 'Invalid Date Example: ';

//Invalid date
$month = 14; // month is wrong
$day = 12;
$year = 2008;

if(checkdate($month, $day, $year))
{
echo 'Date is correct';
}
else
{
echo 'Date is incorrect';
}

?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

No comments:

Post a Comment