Skip to content
Advertisement

How to list last 7 days records in postgresql?

SELECT * FROM dummy WHERE entry_date  between current_date  and current_date at time zone 'UTC' - interval '7 days';

I want to display current date and previous 7 days. the query doesnt work for me.

SELECT * FROM dummy
 WHERE entry_date  between current_date  and current_date at time zone 'UTC' - interval '7 days

Advertisement

Answer

I doubt you have future entry dates. So don’t use between. Instead:

where entry_date >= current_date at time zone 'UTC' - interval '7 days'

Note: If you want to count the current date as a day, then you want interval '6 days'.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement