douqian2524
douqian2524
2017-02-23 06:34
浏览 28
已采纳

如何比较日期和显示记录,只有它在今天和到期之前

I want to display database records only if testfrom date is todays and testto date is not over.

The following code I tried below does not seem to be working well, could someone have a look what am I doing wrong?

the stored date value in the database is

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

my code

    $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){

    }

is this the right way?

Appreciate your valuable time

图片转代码服务由CSDN问答提供 功能建议

我想仅在 testfrom 日期为 todays时显示数据库记录 testto 日期还没有结束。

下面我尝试过的代码似乎运行不正常,有人看看我在做什么 错误?

数据库中存储的日期值是

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

我的代码

  $ dt = date(“Ymd  “); 
 $ srt = date(”Ymd“,strtotime($ r ['testfrom'])); 
 $ end = date(”Ymd“,strtotime($ r ['testto'])); \  n if($ srt&gt; = $ dt || $ end&lt; = $ dt){
 
} 
   
 
 

这是正确的方法吗?< / p>

感谢您的宝贵时间

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudu9094
    doudu9094 2017-02-23 06:48
    已采纳

    change your condition like this:

     $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";
        }
    
    点赞 评论

相关推荐