Home  >  Q&A  >  body text

mysql如何查前两天的数据?

如何实现?

阿神阿神2901 days ago1157

reply all(2)I'll reply

  • 学习ing

    学习ing2016-11-09 16:32:38

    SELECT *FROM Table WHERE datediff(now(),'你表里的日期字段')=2

    reply
    0
  • 汪汪

    汪汪2016-11-09 16:31:58

    //如果数据表中有代表输入时间的insertdate字段,基本可以实现
    //首先取得前两天的日期:
    $yesterday=date("Y-m-d H:i:s",strtotime('-1 day'));
    $thedaybeforeyesterday=date("Y-m-d H:i:s",strtotime('-2 day'));
    $sql=" SELECT * FROM yourtable WHERE insertdate between $yesterday and $thedaybeforeyesterday order by id asc";


    reply
    0
  • Cancelreply