Forked from ValchanOficial/gist:82c4fb2d6e9806a8dfb8c61f2440a6cc
Last active
September 23, 2021 07:54
-
-
Save xyzkpz/f9e7cc7ae95f4ce8c5a6d464875fd2ab to your computer and use it in GitHub Desktop.
How to select records from last 24 hours using SQL?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/a/1888569/11842937 | |
In MySQL: | |
SELECT * | |
FROM mytable | |
WHERE record_date >= NOW() - 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 | |
In Redshift: | |
SELECT * | |
FROM mytable | |
WHERE record_date >= GETDATE() - '1 day'::INTERVAL | |
In SQLite: | |
SELECT * | |
FROM mytable | |
WHERE record_date >= datetime('now','-1 day') | |
In MS Access: | |
SELECT * | |
FROM mytable | |
WHERE record_date >= (Now - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://ubiq.co/database-blog/how-to-select-records-from-last-24-hours-using-postgresql/