| From: | Steve Crawford <scrawford(at)pinpointresearch(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:10:58 |
| Message-ID: | 4D9C9092.3050600@pinpointresearch.com |
| Views: | Whole Thread | Raw Message | 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
> --
> Christine Penner
> Ingenious Software
> 250-352-9495
> chris(at)fp2(dot)ca
Assuming that the field is an int, multiply the value in your years
column by a 1-year interval:
select ii_purchased + your_interval_field * '1 year'::date as date from
inventory_item;
Cheers,
Steve
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Christine Penner | 2011-04-06 16:18:15 | Re: adding years to a date field |
| Previous Message | Adrian Klaver | 2011-04-06 16:05:35 | Re: adding years to a date field |