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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-01-03 19:54:18 Re: DATE_ADD, DATE_SUB, ETC
Previous Message Burra 2002-01-03 18:28:28 DATE_ADD, DATE_SUB, ETC