I want to retrieve yesterday’s record in an exact hour and minute time
For example, this is today’s date and time 2023-04-22 14:32:15
I want the records in 2023-04-21 14:32:15
I tried some queries but non of them works for me:
SELECT CONCAT(
TIMESTAMPDIFF(DAY,'2023-04-21 13:45:00', '2023-04-22 13:45:00'));
SELECT * FROM message
WHERE datetime BETWEEN CURDATE() - INTERVAL 1
DAY AND CURDATE() - INTERVAL 1 HOUR;
2
Answers
Suppose in your SQL table you have column ‘date_time’. Then this type of query you can use :
note : please check your database server have same timezone
Assuming you’ve got a column named
date_column
with typeDateTime
you could use this MySQL sentence to retrieve all records from yesterday fromyour_table
In case
date_column
is atimestamp
field, then useFROM_UNIXTIME()
,UNIX_TIMESTAMP()
andDATE_FORMAT()
accordingly to your needs