Adding a year in PostgreSQL

04 February 2004   1 comment   Linux

Powered by Fusion×

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

 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.


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;

Your email will never ever be published

Related posts

Previous:, can't be good for PayPal 04 February 2004
Techie things I want to buy from 05 February 2004
Related by keywords:
Fastest database for Tornado 09 October 2013
Integer division in programming languages 04 August 2004
Optimization of getting random rows out of a PostgreSQL in Django 23 February 2011
Connecting with psycopg2 without a username and password 24 February 2011
pg_class to check if table exists 20 April 2005
To sub-select or not sub-select in PostgreSQL 31 August 2009
Speed test between django_mongokit and postgresql_psycopg2 09 March 2010
Date formatting in python or in PostgreSQL 20 July 2004
PostgreSQL, MySQL or SQLite 04 April 2004
UPPER vs. ILIKE 19 April 2010
Fastest "boolean SQL queries" possible with Django 14 January 2011
Postgres collation errors on CITEXT fields when upgrading to 9.1 21 May 2012