Mike
Mike

Reputation: 2900

How do I retrieve results from mysql where a timestamp is between 11pm yesterday and 11pm today?

I have a simple mysql table called messages with the following fields:

I simply want to make a query that returns all records where CREATE_DATE is between 11pm yesterday and 11pm today.

When saying yesterday and today I mean by getting the current date from mysql, not hardcoding it in.

Upvotes: 0

Views: 338

Answers (1)

Nicola Cossu
Nicola Cossu

Reputation: 56397

select * from table where create_date 
between concat_ws(' ',curdate(),'23:00:00') - interval 1 day 
and
concat_ws(' ',curdate(),'23:00:00') 

Upvotes: 3

Related Questions