I wrote a little function to check if a date is valid. All the hard stuff is done by the checkdate() function, but function just returns a date if valid or false if not:
function validDate($year,$month,$day) {
if(checkdate($month,$day,$year)) {
return date("Y-m-d", mktime(0,0,0,$month,$day,$year));
} else {
return false;
}
}


You could easily add some checking to see if it's within a range if it's a valid date.


On Thursday, August 21, 2003, at 03:29 PM, Jay Blanchard wrote:


Howdy,

Has anyone written any date validation function or sequence. I have
looked around, but haven't found anything. I am cobbling togather
something, but was hoping to not have to re-invent the wheel. The date
is formatted YYYYMMDD and is input by the user;

$userCentury = substr($userDate, 0, 2); //must be 20 (no problem)
$userYear = substr($userDate, 2, 2); //must be 03 or better
$userMonth = substr($userDate, 4, 2); // 01-12
$userDay = substr($userDate, 6, 2); // 01-31

It doesn't matter if the month is 02 and they have entered 31 as the
day. If any one of the four conditions is not true it gives them a
warning. Anyone done this before?

Thanks!

Jay


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to