开发者

validating dates in PHP

开发者 https://www.devze.com 2023-04-09 10:08 出处:网络
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社区

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.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号