You can use strtotime() and do something like this:
$dateIn = $_POST['dor'];
$dateOut = $_POST['dco'];
if (strtotime($dateIn) < time()) {
echo "Error: Check in date is before today";
}
elseif (strtotime($dateOut) < strtotime($dateIn)) {
echo "Error: Check out date is before check in date";
}
This first confirms that the date of reservation, $dateIn
, is not before the current date. Then confirms that the date of check out, $dateOut
, is not before the date of reservation, $dateIn
.
Note, depending on how your php.ini
is configured, you may need to use date_default_timezone_set() to set the appropriate timezone.
Update:
To implement this into your program, using your current style and setup, just after this block:
else if (!preg_match('/^[1-9][0-9]{0,2}$/', $_POST['num_of_rooms']))
{
.....
}
Add this:
elseif (strtotime($_POST['dor']) < time())
{
echo 'Date of reservation cannot be in the past!';
?>
</br>
Click <a href="reservation.php">here</a> to try again!
<?php
exit();
}
elseif (strtotime($_POST['dco']) < strtotime($_POST['dor']))
{
echo 'Check-out date cannot be before Date of Reservation!';
?>
</br>
Click <a href="reservation.php">here</a> to try again!
<?php
exit();
}