Problem with date calculation

Started by Patrick Ficheover 23 years ago3 messagesgeneral
Jump to latest
#1Patrick Fiche
patrick.fiche@aqsacom.com

Hi,

I'm a newbie to Postgresql and have a problem manipulating dates in a
function...

In fact, I want a function to add some days to the current date and return
the result date.

My code would be something like :

/***************************************************************************
*********/
CREATE OR REPLACE FUNCTION AddDay( int ) RETURNS timestamp AS '

DECLARE
_INTdays ALIAS FOR $1;

_DTcurrent timestamp;

BEGIN

_DTcurrent := NOW() + interval ''_INTdays days'';
RETURN _DTcurrent;

END'
LANGUAGE 'plpgsql';
/***************************************************************************
*********/

I know there is an error in the date calculation but don't know how to
calculate it....

Thanks for your help.

Patrick Fiche

Patrick Fiche
email : patrick.fiche@aqsacom.com
tél : 01 69 29 36 18

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Patrick Fiche (#1)
Re: Problem with date calculation

On Mon, 26 Aug 2002, Patrick FICHE wrote:

Hi,

I'm a newbie to Postgresql and have a problem manipulating dates in a
function...

In fact, I want a function to add some days to the current date and return
the result date.

My code would be something like :

_DTcurrent := NOW() + interval ''_INTdays days'';

I think,
_DTcurrent := NOW() + CAST( _INTdays || '' days'' as interval);

will work.

#3Patrick Fiche
patrick.fiche@aqsacom.com
In reply to: Stephan Szabo (#2)
Re: Problem with date calculation

Thanks a lot, it worked...

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Stephan Szabo
Sent: Monday, August 26, 2002 5:37 PM
To: Patrick FICHE
Cc: PostgreSQL - General (E-mail)
Subject: Re: [GENERAL] Problem with date calculation

On Mon, 26 Aug 2002, Patrick FICHE wrote:

Hi,

I'm a newbie to Postgresql and have a problem manipulating dates in a
function...

In fact, I want a function to add some days to the current date and return
the result date.

My code would be something like :

_DTcurrent := NOW() + interval ''_INTdays days'';

I think,
_DTcurrent := NOW() + CAST( _INTdays || '' days'' as interval);

will work.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)