Re: How to add days to date

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "Alejandro Michelin Salomon ( Adinet )" <alejmsg(at)adinet(dot)com(dot)uy>
Cc: Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to add days to date
Date: 2006-08-16 01:16:56
Message-ID: 20060816011656.GA3453@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Aug 15, 2006 at 10:10:27PM -0300, Alejandro Michelin Salomon ( Adinet ) wrote:
> EX :
> '2006-08-01' + 30 + ( 7 * ( 3 - 1 )) ==> '2006-08-01' + 44
>
> All my trys fails.

The error message hints at what's wrong:

test=> SELECT '2006-08-01' + 30 + (7 * (3 - 1));
ERROR: invalid input syntax for integer: "2006-08-01"

PostgreSQL doesn't know that the untyped string is supposed to be
interpreted as a date. Use a cast:

test=> SELECT '2006-08-01'::date + 30 + (7 * (3 - 1));
?column?
------------
2006-09-14
(1 row)

or

test=> SELECT CAST('2006-08-01' AS date) + 30 + (7 * (3 - 1));
?column?
------------
2006-09-14
(1 row)

--
Michael Fuhr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2006-08-16 01:31:31 Re: Connection string
Previous Message Alejandro Michelin Salomon ( Adinet ) 2006-08-16 01:10:27 How to add days to date