Re: adding years to a date field

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Christine Penner <chris(at)fp2(dot)ca>
Cc: Postgres-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: adding years to a date field
Date: 2011-04-06 16:05:35
Message-ID: 4D9C8F4F.9000109@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/06/2011 08:54 AM, Christine Penner wrote:
> I have to add a number of years to a date field. The years come from
> another field in the table.
>
> I know I can do this:
> select (ii_purchased + interval '3 year') as date from inventory_item;
>
> But I need to replace the 3 in 3 years with another field from the same
> table ii_expected_life but I can't seem to do that without getting
> syntax errors

Maybe something along lines:
select (ii_purchased + interval year_int::text||' year') as date from
inventory_item

I am guessing at the data type of the field.

>
> --
> Christine Penner
> Ingenious Software
> 250-352-9495
> chris(at)fp2(dot)ca
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2011-04-06 16:10:58 Re: adding years to a date field
Previous Message Andrew Sullivan 2011-04-06 16:04:42 Re: temp tables not dropping at end of script