Re: SELECT and DATE Function question

From: "Mike C" <smith(dot)not(dot)western(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: SELECT and DATE Function question
Date: 2006-09-11 05:34:03
Message-ID: bd0eabd0609102234x5ce6f51by68240306a7083313@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

That works great, thank you!

Mike

On 9/11/06, Aaron Bono <postgresql(at)aranya(dot)com> wrote:
>
> On 9/10/06, Mike C <smith(dot)not(dot)western(at)gmail(dot)com> wrote:
>
> > Hi,
> >
> > I'm trying to calculate an expiration date by adding the number of days
> > onto the start date. i.e. select start_date + number_of_days from blah;
> >
> > create table blah (start_date timestamp, number_of_days integer);
> > insert into blah values (current_timestamp, 25);
> > select start_date + number_of_days from blah;
> >
> > The error I get is:
> >
> > ERROR: operator does not exist: timestamp without time zone + integer
> > HINT: No operator matches the given name and argument type(s). You may
> > need to add explicit type casts.
> >
> > But according to http://www.postgresql.org/docs/8.1/static/functions-datetime.html
> > the + operator should support integers and treat them as days ( date
> > '2001-09-28' + integer '7'). Obviously typing a constant into the query is a
> > lot different from using the value of a column, but I would have thought it
> > would work.
> >
> > What is the correct way to make this calculation?
> >
>
>
> Use:
>
> select start_date + (cast(number_of_days as text) || ' days')::interval
> from blah
>
> See http://www.postgresql.org/docs/8.1/interactive/functions-datetime.htmlfor more
>
> ==================================================================
> Aaron Bono
> Aranya Software Technologies, Inc.
> http://www.aranya.com
> http://codeelixir.com
> ==================================================================
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jason Topaz 2006-09-11 07:29:32 Re: SELECT and DATE Function question
Previous Message Aaron Bono 2006-09-11 05:27:46 Re: SELECT and DATE Function question