2016-12-02 60 views
-1

我正在開發一個插件,但我無法正常工作。PHP如果在兩個日期之間

下面的代碼應該在當前日期介於用戶選擇的2個日期之間時執行某些操作。

所以,如果日期是在2016年12月1日($snow['period_past'])和明天之間,2016年12月3日($snow['period_future']),做一些事情......

$date = date('Y-m-d'); 
$date = date('Y-m-d', strtotime($date)); 

$snowStart = date('Y-m-d', strtotime($snow['period_past'])); 
$snowEnd = date('Y-m-d', strtotime($snow['period_future'])); 

if (($date > $snowStart) && ($date < $snowEnd)) { 
     // do this and that 
} 

上述工程的代碼,但只有它在日期之間工作。如何使其工作,以便它在$snow['period_past']日期和$snow['period_future']日期的時候也能正常工作?

對不起,我的錯誤解釋是,英語不是我的母語。

+2

使用'> ='和'<='.... –

+0

不知道你到底想要做什麼...也許> = <= –

+0

[PHP檢查兩個日期之間的日期]可能的重複(http://stackoverflow.com/questions/19070116/php-check-if日期之間) – jycr753

回答

1
if (($date >= $snowStart) && ($date <= $snowEnd)) 
{ 
    // do this and that 
} 
+0

'語法錯誤,意外的'<''? – Jerrald

+0

現在檢查..我更新了代碼。 –

+0

工作,謝謝! – Jerrald

1

你正在做一個greater than>less than<比較。

要獲得條件滿足時的日期等於$snow['period_past']$snow['period_future'],你應該在的地方如下比較:

if (($date >= $snowStart) && ($date =< $snowEnd)) 
{ 
    // your code here 
} 
+0

謝謝,我懂了 – Jerrald

相關問題