Home » Mysql » Find records with a date field in the last 24 hours [duplicate]

Find records with a date field in the last 24 hours [duplicate]

Posted by: admin November 1, 2017 Leave a comment

Questions:

This question already has an answer here:

Answers:

You simply select dates that are higher than the current time minus 1 day.

SELECT * FROM news WHERE date >= now() - INTERVAL 1 DAY;

Questions:
Answers:
SELECT * FROM news WHERE date > DATE_SUB(NOW(), INTERVAL 24 HOUR)

Questions:
Answers:
SELECT * from new WHERE date < DATE_ADD(now(),interval -1 day);

Questions:
Answers:
SELECT * FROM news WHERE date > DATEADD(d,-1,GETDATE())

Questions:
Answers:

check:

SELECT * from [table_name] WHERE date > (NOW() - INTERVAL 24 HOUR).

Questions:
Answers:

There are so many ways to do this. The listed ones work great, but here’s another way if you have a datetime field:

SELECT [fields] 
FROM [table] 
WHERE timediff(now(), my_datetime_field) < '24:00:00'

timediff() returns a time object, so don’t make the mistake of comparing it to 86400 (number of seconds in a day), or your output will be all kinds of wrong.

Questions:
Answers:
SELECT * FROM news WHERE date < DATEADD(Day, -1, date)