-1
中兩個日期的正確方法我有一個簡單的表單讓用戶選擇要提交的日期。
現在在PHP中,我想確保用戶提交的日期不會超過今天的當前日期。
這裏我使用Php date()
。比較Php
//process.php
$date_from = $_POST['date_from'];//submitted by user
$date_to = $_POST['date_to'];//submitted by user
$date_now = date('Y-m-d');//this should be the current date
if($date_from > $date_now || $date_to > $date_now)
{
$error = "Your search date should not greater than today's date";
}
else
{
//process data
}
但它不工作。
將今天的日期與用戶提交的日期進行比較的正確方法是什麼?
檢查這個http://stackoverflow.com/questions/8722806/how-to-compare-two-dates-in-php – 2014-12-02 04:03:32
我認爲做'strtotime()'是一個很好的方法來改變你的日期,以便能夠比較它們。 – Rasclatt 2014-12-02 04:10:50