mysql: get record count between two date-time

2019-01-05 03:08发布

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' having the datetime data type.

I want to count records which were created date-time between "TODAY'S 4:30 AM" and "CURRENT DATE TIME".

I tried some of MySQL's functions but still no luck with it.

Can you please help me with this? thanks.

3条回答
迷人小祖宗
2楼-- · 2019-01-05 03:21
select * from yourtable where created < now() and created > '2011-04-25 04:00:00'
查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-05 03:36

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.

查看更多
走好不送
4楼-- · 2019-01-05 03:40
select * from yourtable 
   where created < now() 
     and created > concat(curdate(),' 4:30:00 AM') 
查看更多
登录 后发表回答