Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find records added to my database table in the past 24 hours?

Tags:

sql

I'm using MySQL in particular, but I'm hoping for a cross-vendor solution. I'm using the NOW() function to add a timestamp as a column for each record.

INSERT INTO messages 
(typeId, messageTime, stationId, message) 
VALUES 
(?, NOW(), ?, ?)
like image 724
Bill the Lizard Avatar asked Mar 01 '23 08:03

Bill the Lizard


1 Answers

SELECT * FROM messages WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= messageTime
like image 85
Alexander Morland Avatar answered Apr 06 '23 04:04

Alexander Morland