Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From Now() to Current_timestamp in Postgresql

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 ?

like image 982
xRobot Avatar asked Jun 07 '10 21:06

xRobot


People also ask

What is the difference between now () and CURRENT_TIMESTAMP?

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() .

What is now () in PostgreSQL?

The PostgreSQL now function returns the current date and time with the time zone.

What is CURRENT_TIMESTAMP in PostgreSQL?

The PostgreSQL CURRENT_TIMESTAMP() function returns the current date and time with time zone, which is the time when the transaction starts.

How do I get the current date and time in PostgreSQL?

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.


1 Answers

Use an interval instead of an integer:

SELECT * FROM table WHERE auth_user.lastactivity > CURRENT_TIMESTAMP - INTERVAL '100 days' 
like image 94
Mark Byers Avatar answered Oct 25 '22 18:10

Mark Byers