In mysql I am able to do this:
SELECT * FROM table WHERE auth_user.lastactivity > NOW() - 100
now in postgresql I am using this query:
SELECT * FROM table WHERE auth_user.lastactivity > CURRENT_TIMESTAMP - 100
but I get this error:
operator does not exist: timestamp with time zone - integer
How can I resolve ?
NOW() returns a constant time that indicates the time at which the statement began to execute. NOW() returns the time at which the function or triggering statement began to execute, but SYSDATE() returns the exact time at which it executes. And CURRENT_TIMESTAMP , CURRENT_TIMESTAMP() are synonyms for NOW() .
The PostgreSQL now function returns the current date and time with the time zone.
The PostgreSQL CURRENT_TIMESTAMP() function returns the current date and time with time zone, which is the time when the transaction starts.
Postgresql now() The NOW() function in Postgresql is used to get the current date and time. The return type of the NOW() function is the timestamp with the time zone. We can fetch the current date and time by using the PostgreSQL NOW() function. This function has a return type i.e. the timestamp with the time zone.
Use an interval instead of an integer:
SELECT * FROM table WHERE auth_user.lastactivity > CURRENT_TIMESTAMP - INTERVAL '100 days'
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