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
Form Date Validation
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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';
}