What where clause should be use to get records from the last 24 hours?
A:
select * from table_name where date_col > sysdate-1; //Oracle
select * from table_name where date_col > now()-1; //Mysql
DKSRathore
2009-12-11 14:52:15
+6
A:
In MySQL
:
SELECT *
FROM mytable
WHERE record_date >= SYSDATE() - INTERVAL 1 DAY
In SQL Server
:
SELECT *
FROM mytable
WHERE record_date >= DATEADD(day, -1, GETDATE())
In Oracle
:
SELECT *
FROM mytable
WHERE record_date >= SYSDATE - 1
In PostgreSQL
:
SELECT *
FROM mytable
WHERE record_date >= NOW() - '1 day'::INTERVAL
Quassnoi
2009-12-11 14:52:27
A:
SELECT *
FROM tableName
WHERE datecolumn >= dateadd(hour,-24,getdate())
Galwegian
2009-12-11 14:53:04
+1
A:
Which SQL was not specified, SQL 2005 / 2008
SELECT yourfields from yourTable WHERE yourfieldWithDate > dateadd(dd,-1,getdate())
If you are on the 2008 increased accuracy date types, then use the new sysdatetime() function instead, equally if using UTC times internally swap to the UTC calls.
Andrew
2009-12-11 14:54:18
+2
A:
SELECT *
FROM table_name
WHERE table_name.the_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY)
Guillaume Flandre
2009-12-11 14:54:40
If the records are stored as `DATETIME`, this will select all records from the previous date, disregarding the time part. Been run at `23:59:59`, the query will return all records for the last `48` hours, not `24`.
Quassnoi
2009-12-11 15:02:30