validating dates in PHP
can anyone taught me a function or a script or some related example where in it would only allow number of days to be inputted? I have a datepicker for choosing the date start 开发者_StackOverflow社区and date end... I only want the user to input within a specified range of time/date and if the user overlaps, it will prompt the user that they could only input from a certain range of time.
Ex. I would only allow 28 days.
Scenario1:
Date from: 2011-09-01
Date to: 2011-09-31
Result: (prompt) you are only allowed to input within 28 days.
Scenario2:
Date from: 2011-09-01
Date to: 2011-09-20
Result: it will proceed to another page.
If you have >= PHP 5.3...
$startDate = new DateTime('2011-09-01');
$endDate = new DateTime('2011-09-31');
$diff = $startDate->diff($endDate);
if ($diff->d > 28) {
// More than 28 days.
}
精彩评论