Adding a year in PostgreSQL

04 February 2004   1 comment   Linux

http://www.postgresql.org/docs/7.4/static/functions-datetime.html#OPERATORS-DATETIME-TABLE

Mind That Age!

This blog post is 13 years old! Most likely, its content is outdated. Especially if it's technical.

Powered by Fusion×

Finally I found it. How to add one year to a date in PostgreSQL

SELECT 
 date('now') + interval '1 year' AS today_in_one_year,
 date '2003-12-13' + interval '1 year' AS my_next_birthday ;

Both return a TIMESTAMP type.

Follow @peterbe on Twitter

Comments

Peter
UPDATE: It doesn't return a TIMESTAMP type, it's a DATE type (only 4 bytes).

To get a TIMESTAMP you can do this:

SELECT '2003-12-13' + interval '1 year' AS my_next_birthday;
Thank you for posting a comment

Your email will never ever be published


Related posts

Previous:
PayPalSucks.com, can't be good for PayPal 04 February 2004
Next:
Techie things I want to buy from ebuyer.com 05 February 2004
Related by Keyword:
How do log ALL PostgreSQL SQL happening 20 July 2015
Fastest database for Tornado 09 October 2013
Postgres collation errors on CITEXT fields when upgrading to 9.1 21 May 2012
Connecting with psycopg2 without a username and password 24 February 2011
Optimization of getting random rows out of a PostgreSQL in Django 23 February 2011
Related by Text:
Interesting lesson learnt on shortcut taking in usability 02 August 2007
Crossing the world - new feature on Crosstips 23 May 2009
Django forms and making datetime inputs localized 04 December 2015
"Clever" date formatting accessibility 10 November 2005
Autosaving textarea with AJAX 16 May 2005