I am looking for a where
clause that can be used to retrieve records for the last 24 hours?
In SQL Server (For last 24 hours):
SELECT *
FROM mytable
WHERE order_date > DateAdd(DAY, -1, GETDATE()) and order_date<=GETDATE()
SELECT *
FROM tableName
WHERE datecolumn >= dateadd(hour,-24,getdate())
select ...
from ...
where YourDateColumn >= getdate()-1
MySQL :
SELECT *
FROM table_name
WHERE table_name.the_date > DATE_SUB(NOW(), INTERVAL 24 HOUR)
The INTERVAL can be in YEAR, MONTH, DAY, HOUR, MINUTE, SECOND
For example, In the last 10 minutes
SELECT *
FROM table_name
WHERE table_name.the_date > DATE_SUB(NOW(), INTERVAL 10 MINUTE)
If the timestamp considered is a UNIX timestamp You need to first convert UNIX timestamp (e.g 1462567865) to mysql timestamp or data
SELECT * FROM `orders` WHERE FROM_UNIXTIME(order_ts) > DATE_SUB(CURDATE(), INTERVAL 1 DAY)
SELECT *
FROM table_name
WHERE table_name.the_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY)