我已經爲出租車公司建立了一個預訂表單,但工作正常,但我遇到了問題,因爲用戶提出的預訂過期在將來。驗證時間和日期至少在未來的某個時間段
由於整個表格很長,所以我首先要確保用戶不會在不到一個小時的時間內進行預留,而無需填寫整個表格。
這就是我來了這麼遠,但它只是不工作:
<?php
//Set local time zone.
date_default_timezone_set('America/New_York');
//Get current date and time.
$current_time = date('Y-m-d H:i:s');
//Set reservation time variable
$res_datetime = $_POST['res_datetime'];
//Set event time.
$event_time = strtotime($res_datetime);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Check Date and Time</title>
</head>
<?php
//Check to be sure reservation time is at least one hour in the future.
if (($current_time - $event_time) <= (3600))
{
echo "You must make a reservation at least one hour ahead of time.";
}
?>
<form name="datetime" action="" method="post">
<input name="res_datetime" type="datetime-local" id="res_datetime">
<input type="submit">
</form>
<body>
</body>
</html>
如何創建一個驗證檢查,以確保預約的日期和時間是至少一小時提前時間?
事件時間 - 當前時間> 3600. –
這裏有很多錯誤。我建議你在開始驗證之前先看看一個好的Forms教程,例如[W3Schools](http://www.w3schools.com/php/php_forms.asp)來整理表單處理。當你到達這一點時,使用Unix時間戳記你的日期,然後檢查差異是否大於3600將做你所需要的。 – 2013-07-02 23:03:55
不,對於DST's_上帝之神,不要加上_think_會_always_意思是「一個小時」 - 使用strtotime('+ 1小時')'(並將其與'time()'比較) 。 – CBroe