【问题标题】:how do I compare date and display record only if its in todays and before expiry只有在今天和到期之前,我如何比较日期和显示记录
【发布时间】:2017-02-23 06:34:20
【问题描述】:

我只想在testfrom 日期为todaystestto 日期未结束时才显示数据库记录。

我在下面尝试的以下代码似乎无法正常工作,有人可以看看我做错了什么吗?

数据库中存储的日期值是

testfrom - 2017-02-23 00:00:00
testto - 2017-02-24 23:59:59

我的代码

    $dt = date("Y-m-d");
    $srt = date("Y-m-d", strtotime($r['testfrom']));
    $end = date("Y-m-d", strtotime($r['testto']));
 if($srt >= $dt || $end <= $dt){

    }

这是正确的方法吗?

珍惜你宝贵的时间

【问题讨论】:

标签: php mysql date-comparison


【解决方案1】:

像这样改变你的条件:

 $dt = date("Y-m-d");
    $srt = date("Y-m-d", strtotime("2017-02-23 00:00:00"));
    $end = date("Y-m-d", strtotime("2017-02-24 23:59:59"));
 if($srt == $dt && $end >= $dt){
  echo "yes";
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 2014-09-09
    相关资源
    最近更新 更多