Home > Blockchain >  How to get last 1 hour to last 10 days data in mysql
How to get last 1 hour to last 10 days data in mysql

Time:06-18

I need to get data within a range which starts a hour ago. As an example if now time is 08.00 AM, I need to get all the data within 07.00 AM to last 10 days. I have tried with datesub function as below, But seems this is wrong because the date(now()) and date(now()-interval 1 hour) are both same.. Can someone show me how to get this?

.....and date(time)>date(date_sub((now()-interval 1 hour), interval 10 day)) group by ds.....

CodePudding user response:

Assuming time field in your query is either timestamp or datetime.

... and time between cast(concat(date_sub(curdate(), INTERVAL 10 day), ' 00:00:00') as datetime) and DATE_SUB(now(), INTERVAL 1 hour)

Hope this will help.

  • Related