Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get exact now time of yesterday day data mysql

I want to get yesterday’s record in exact now hour and minute time

Forexample 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 like bottom but non of them works:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;

>Solution :

Suppose in your SQL table you have column ‘date_time’. Then this type of query you can use :

select * from table_name
where date(date_time)=date(now()-interval 1 day)
and hour (date_time)=hour(now()
and minute(date_time)=minute(now();

note : please check your database server have same timezone

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading