PostgreSQL: How to Select Records Entered Over the Last Day

To select records (e.g. from an errors table) created between now and a day ago, you can use the interval syntax:

select * from errors
    where date_entered > (now() - (interval '1 day'))

If you'd like to select over the past 3 days, you can use a multiplier with the interval:

select * from errors
    where date_entered > (now() - (3 * interval '1 day'))

Comments

Leave a comment

What color are brown eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.