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

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.

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:
How do log ALL PostgresSQL 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
Fastest "boolean SQL queries" possible with Django 14 January 2011
UPPER vs. ILIKE 19 April 2010
Speed test between django_mongokit and postgresql_psycopg2 09 March 2010
To sub-select or not sub-select in PostgreSQL 31 August 2009
Why bother with MySQL... 09 October 2008