Page 1 of 1
Form Date Validation
Posted: Wed May 11, 2005 9:03 am
by rlwillis
Hi Folks, I have an order form with a "product delivery date" entry. The delivery date request must be at least 30 days from the current date. How would I validate this?
Thanks for any consideration.
rlwillis
Posted: Wed May 11, 2005 9:14 am
by Chris Corbyn
You need to get the date they input into US style date format mm/dd/YYYY and then you can do some calculations by converting it to a timestamp using
strtotime().
Code: Select all
//Example input date
$in_date = '05/25/2005'; //25th May 2005
$in_stamp = strtotime($in_date); //Unix timestamp of 25th May 2005 in seconds
$now = time(); //The unix timestamp now
if ($in_date - $now > (60 * 60 * 24 * 30)) { //secs * mins * hours * days
echo 'Date is more than 30 days from now';
} else {
echo 'Date is within 30 days of now';
}
Posted: Wed May 11, 2005 10:01 am
by rlwillis
Thanks!