Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: Timestamp in the future

How can I get a timestamp with a date 30 days from now?

I tried things like now() + integer '30'... but it didn't work.

I'm running Postgres 8.

Any ideas?

like image 397
paoloP Avatar asked May 06 '11 16:05

paoloP


People also ask

What is the future of PostgreSQL?

The next major release of PostgreSQL is planned to be the 16 release. A tentative schedule for this version has a release in the third quarter of 2023.

Should I use timestamp or Timestamptz?

Timestamp vs Timestamptz – What's the Difference? The big difference between these two data types is that timestamptz includes a timezone offset while timestamp does not. So it is important to decide for the timestamp you are storing whether the timezone is important to keep or not.

Does Postgres support timestamp?

PostgreSQL supports the full set of SQL date and time types, shown in Table 8.9.

How does Postgres store timestamps?

PostgreSQL stores the timestamptz in UTC value. When you insert a value into a timestamptz column, PostgreSQL converts the timestamptz value into a UTC value and stores the UTC value in the table.


2 Answers

Try something like this:

SELECT NOW() + '30 days'::interval
like image 89
Szymon Lipiński Avatar answered Nov 12 '22 05:11

Szymon Lipiński


The standard SQL expression is

select current_timestamp + interval '30' day

Quotes around the number, not around the phrase. See the earliest SQL standard I can find online, p 91. PostgreSQL is much more flexible than the standard, which can be a good thing or a bad thing. I support a lot of different dbms--the flexibility hurts me more often than it helps. PostgreSQL, for example, supports this non-standard statement.

select current_timestamp + interval '1 month, 2 days, 3 hours, 2 minutes';
like image 24
Mike Sherrill 'Cat Recall' Avatar answered Nov 12 '22 06:11

Mike Sherrill 'Cat Recall'