Skip site navigation (1) Skip section navigation (2)

Re: DATE_ADD, DATE_SUB, ETC

From: Jason Earl <jason(dot)earl(at)simplot(dot)com>
To: Burra <burra(at)colorado(dot)edu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: DATE_ADD, DATE_SUB, ETC
Date: 2002-01-03 19:29:46
Message-ID: 877kqz5j2t.fsf@npa01zz001.simplot.com (view raw or flat)
Thread:
Lists: pgsql-novice
Uh, I think that you would be surprised what PostgreSQL will let you
do without special functions.

For example:

SELECT '2001-01-01'::timestamp + '1 year'::interval;

        ?column?        
------------------------
 2002-01-01 00:00:00-07


You don't even need the explicit casts if the database knows the type
already.  Subtracting timestamps gets you an interval, and intervals
and timestamps can be added (or subtracted) to get a timestamp result.

Jason

Burra <burra(at)colorado(dot)edu> writes:

> Does postgres have functions that are similar to these mysql functions?
> 
> DATE_ADD(date,INTERVAL expr type)
> DATE_SUB(date,INTERVAL expr type)
> ADDDATE(date,INTERVAL expr type)
> SUBDATE(date,INTERVAL expr type)
> 
> --------------------[-- burra(at)colorado(dot)edu --]--------------------------
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html

In response to

pgsql-novice by date

Next:From: Josh BerkusDate: 2002-01-03 19:54:18
Subject: Re: DATE_ADD, DATE_SUB, ETC
Previous:From: BurraDate: 2002-01-03 18:28:28
Subject: DATE_ADD, DATE_SUB, ETC

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group