在 PHP 中验证日期

发布于 2024-12-07 01:10:07 字数 399 浏览 1 评论 0原文

谁能教我一个函数或脚本或一些相关示例,其中只允许输入天数?我有一个日期选择器用于选择日期开始和日期结束...我只希望用户在指定的时间/日期范围内输入,如果用户重叠,它会提示用户只能从某个范围内输入的时间。

前任。我只允许28天。

场景 1:

Date from: 2011-09-01
Date to: 2011-09-31

Result: (prompt) you are only allowed to input within 28 days.

场景 2:

Date from: 2011-09-01
Date to: 2011-09-20

Result: it will proceed to another page.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森罗 2024-12-14 01:10:07

如果您有 >= 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.
}

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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文