Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Last 7 days from postgres table epoch timestamp

Tags:

postgresql

I have a table (funny_quotes) which has a column called quote_date and it stores data in unix epoch time (seconds)

I want to run a query to only return data from this table(funny_quotes) only from the last 3 days.

I created a table locally in postgres but unable to store dates as epoch time, they only get stored as timestamp values

select * from funny_quotes where quote_date > (now() - interval '3 days')

like image 771
Vik G Avatar asked Dec 20 '25 03:12

Vik G


1 Answers

You should modify the right side of the equation to epoch in order to be able to compare:

select * from funny_quotes where quote_date > extract(epoch from (now() - interval '3 days'))

Or the other way around: convert quote_date into timestamp:

select * from funny_quotes where to_timestamp(quote_date) > now() - interval '3 days'

You can read more about it in the docs

like image 94
Nir Alfasi Avatar answered Dec 24 '25 09:12

Nir Alfasi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!