my database is using an integer in epoch time for date in this table.
I want to do something like this:
select * from myTable where date_column > CURRENT_TIMESTAMP - 6 months
I'm not sure how to get 6 months out of this, dynamically. And the result of CURRENT_TIMESTAMP - 6 months
would have to be in epoch time
insight appreciated
In Postgres, I believe the correct syntax is:
date_column > EXTRACT('epoch' from (NOW() - interval ' 6 months'))
or similarly:
to_timestamp(date_column) > (NOW() - interval ' 6 months'))
You can read the complete documentation of the date/time functions for Postgres for more information
In MSSQL you can use
select *
from myTable
where date_column > dateadd(month,-6,CURRENT_TIMESTAMP)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With