Joe Schmoe Joe Schmoe - 5 months ago 35
MySQL Question

how do i get mysql rows from 24-48 hours ago?

I have a mysql table with a datetime column. I want to fetch rows which are older than 24 hours but younger than 48 hours. Ive gone through the date time function not quite sure how to approach this or what to do in general.

Answer

Use:

SELECT *
  FROM YOUR_TABLE t
 WHERE t.datetime_column < DATE_SUB(NOW(), INTERVAL 24 HOUR)
   AND t.datetime_column > DATE_SUB(NOW(), INTERVAL 48 HOUR)