【发布时间】:2016-09-13 00:34:47
【问题描述】:
在表单上,用户必须输入出生日期。 PHP应该控制他是否已经完成了18年。
$birth = $_POST['data_nascita'];
$str_birth = strtotime ($birth );
$today = date("m/d/Y");
$str_today = strtotime ($today);
if($today - $str_today < 567648000) {
echo'you can't drive a car in Italy because you are underage';exit();
}
// 18 years * 31536000 second in 1 year = 567648000
如果我在出生字段上输入 1998 年 9 月 14 日的日期(今天是 2016 年 9 月 13 日,所以 18 年还没有完全用完),控制不起作用;它从 1998 年 9 月 15 日开始工作。
为什么我输了 2 天?
【问题讨论】:
标签: php forms date timestamp strtotime