mysql: get record count between two date-time

后端 未结 4 986
孤城傲影
孤城傲影 2020-11-27 05:09

I am stuck with a problem in MySQL. I want to get the count of records between two date-time entries.
For example:
I have a column in my table named \'created\' havi

相关标签:
4条回答
  • for speed you can do this

    WHERE date(created_at) ='2019-10-21'
    
    0 讨论(0)
  • 2020-11-27 05:27

    May be with:

    SELECT count(*) FROM `table` 
    where 
        created_at>='2011-03-17 06:42:10' and created_at<='2011-03-17 07:42:50';
    

    or use between:

    SELECT count(*) FROM `table` 
    where 
        created_at between '2011-03-17 06:42:10' and '2011-03-17 07:42:50';
    

    You can change the datetime as per your need. May be use curdate() or now() to get the desired dates.

    0 讨论(0)
  • 2020-11-27 05:32
    select * from yourtable where created < now() and created > '2011-04-25 04:00:00'
    
    0 讨论(0)
  • 2020-11-27 05:40
    select * from yourtable 
       where created < now() 
         and created > concat(curdate(),' 4:30:00 AM') 
    
    0 讨论(0)
提交回复
热议问题