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 by keywords:
Connecting with psycopg2 without a username and password 24 February 2011
Integer division in programming languages 04 August 2004
Fastest database for Tornado 09 October 2013
pg_class to check if table exists 20 April 2005
Optimization of getting random rows out of a PostgreSQL in Django 23 February 2011
To sub-select or not sub-select in PostgreSQL 31 August 2009
UPPER vs. ILIKE 19 April 2010
Date formatting in python or in PostgreSQL 20 July 2004
Speed test between django_mongokit and postgresql_psycopg2 09 March 2010
PostgreSQL, MySQL or SQLite 04 April 2004
Fastest "boolean SQL queries" possible with Django 14 January 2011
List of casts in PostgreSQL 09 May 2005