【问题标题】:PHP if between 2 datesPHP 如果在 2 个日期之间
【发布时间】:2016-12-02 20:05:36
【问题描述】:

我正在开发一个插件,但我无法让它工作。

当当前日期在用户选择的两个日期之间时,下面的代码应该做一些事情。

所以如果日期在 12-01-2016 ($snow['period_past']) 和明天是 12-03-2016 ($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'] 日期时也能工作?

对不起,我的解释不好,英语不是我的母语。

【问题讨论】:

  • 使用&gt;=&lt;=....
  • 不确定你到底想做什么...也许 >=
  • @jycr753 很抱歉,这个问题不是重复的,请阅读我的帖子,让你明白我的意思
  • @JeremyHarris 这就是我要找的,谢谢

标签: php date


【解决方案1】:
if (($date >= $snowStart) && ($date <= $snowEnd)) 
{
     // do this and that
}

【讨论】:

    【解决方案2】:

    您正在进行greater than &gt;less than &lt; 比较。

    要在日期等于$snow['period_past']$snow['period_future'] 时满足条件,您应该有以下比较:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      • 2019-07-28
      相关资源
      最近更新 更多