Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 831
Joe Schmoe Avatar asked Oct 06 '10 02:10

Joe Schmoe


People also ask

How do I select records from the last 24 hours in SQL Server?

If you want to select the last 24 hours from a datetime field, substitute 'curate()' with 'now()'. This also includes the time.

How do I get 24 hours in MySQL?

In the above SQL query, we use MySQL system function now() to get current datetime. Then we use INTERVAL clause to select those rows where order_date falls within past 24 hours of present datetime. Instead of specifying interval in hours, you can also mention it in day.

How can I get specific date records in MySQL?

You can use DATE() from MySQL to select records with a particular date. The syntax is as follows. SELECT *from yourTableName WHERE DATE(yourDateColumnName)='anyDate'; To understand the above syntax, let us first create a table.

How can I get records between two dates in MySQL?

select *from yourTableName where yourColumnName between 'yourStartingDate' and curdate().


1 Answers

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) 
like image 169
OMG Ponies Avatar answered Sep 20 '22 17:09

OMG Ponies