PHP如果在两个日期之间

问题描述:

我正在开发一个插件,但我无法正常工作。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://*.com/questions/19070116/php-check-if日期之间) – jycr753

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

'语法错误,意外的' Jerrald

+0

现在检查..我更新了代码。 –

+0

工作,谢谢! – Jerrald

你正在做一个greater than>less than<比较。

要获得条件满足时的日期等于$snow['period_past']$snow['period_future'],你应该在的地方如下比较:

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

谢谢,我懂了 – Jerrald