Re: Date addition/subtraction

From: Ragnar Hafstað <gnari(at)simnet(dot)is>
To: Craig Bryden <postgresql(at)bryden(dot)co(dot)za>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Date addition/subtraction
Date: 2005-05-03 18:08:30
Message-ID: 1115143710.5853.48.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2005-05-03 at 19:32 +0200, Craig Bryden wrote:
>
> How in postgres can I do date/time subtraction or addition.
> e.g. If I want to get today's date - 30 days? or current_timestamp - 1 hour?

easier than you think

select current_timestamp - interval '1 hour';
select current_date -interval '30 days'; -- timestamp
select current_date + interval '1 week'; -- timestamp
select date (current_date + interval '1 week'); -- date

see:
http://www.postgresql.org/docs/8.0/interactive/functions-datetime.html

gnari

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ragnar Hafstað 2005-05-03 18:14:04 Re: Sorting by constant values
Previous Message Scott Marlowe 2005-05-03 17:53:19 Re: Sorting by constant values