
I'm trying to use an integer from a table to add/subtract time in months.
IOW:

create table foo(nummonths int);

select now() - nummonths months;

So far nothing I've tried will work - short of a function.  Is there a
way to do this?

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH    email: vev@michvhf.com    http://www.pop4.net
         56K Nationwide Dialup from $16.00/mo at Pop4 Networking
        Online Campground Directory    http://www.camping-usa.com
       Online Giftshop Superstore    http://www.cloudninegifts.com
==========================================================================




Wed, 26 Sep 2001 16:30:52 -0400 (EDT)
Vince Vielhaber <vev@michvhf.com>
casting for dates
Will

SELECT now() - 'nummonths months'::interval ;

work?


----- Original Message -----
From: "Vince Vielhaber" <vev@michvhf.com>
To: <pgsql-hackers@postgresql.org>
Sent: Wednesday, September 26, 2001 4:30 PM
Subject: [HACKERS] casting for dates


>
> I'm trying to use an integer from a table to add/subtract time in months.
> IOW:
>
> create table foo(nummonths int);
>
> select now() - nummonths months;
>
> So far nothing I've tried will work - short of a function.  Is there a
> way to do this?
>
> Vince.
> --
> ==========================================================================
> Vince Vielhaber -- KA8CSH    email: vev@michvhf.com    http://www.pop4.net
>          56K Nationwide Dialup from $16.00/mo at Pop4 Networking
>         Online Campground Directory    http://www.camping-usa.com
>        Online Giftshop Superstore    http://www.cloudninegifts.com
> ==========================================================================
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>


Wed, 26 Sep 2001 16:52:16 -0400
"Mitch Vincent" <mvincent@cablespeed.com>
Re: casting for dates
On Thu, 2001-09-27 at 08:30, Vince Vielhaber wrote:
> 
> I'm trying to use an integer from a table to add/subtract time in months.
> IOW:
> 
> create table foo(nummonths int);
> 
> select now() - nummonths months;

newsroom=# select now() - interval( text(3) || ' months');
        ?column?        
------------------------
 2001-06-27 08:56:27+12
(1 row)


Crude, but hey: it works :-)

Cheers,
					SAndrew.
-- 
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/        PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7217    MOB: +64(21)635-694    OFFICE: +64(4)499-2267


27 Sep 2001 08:57:19 +1200
Andrew McMillan <andrew@catalyst.net.nz>
Re: casting for dates
On 27 Sep 2001, Andrew McMillan wrote:

> On Thu, 2001-09-27 at 08:30, Vince Vielhaber wrote:
> >
> > I'm trying to use an integer from a table to add/subtract time in months.
> > IOW:
> >
> > create table foo(nummonths int);
> >
> > select now() - nummonths months;
>
> newsroom=# select now() - interval( text(3) || ' months');
>         ?column?
> ------------------------
>  2001-06-27 08:56:27+12
> (1 row)
>
>
> Crude, but hey: it works :-)

It certainly does!  Thanks!

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH    email: vev@michvhf.com    http://www.pop4.net
         56K Nationwide Dialup from $16.00/mo at Pop4 Networking
        Online Campground Directory    http://www.camping-usa.com
       Online Giftshop Superstore    http://www.cloudninegifts.com
==========================================================================




Wed, 26 Sep 2001 17:19:27 -0400 (EDT)
Vince Vielhaber <vev@michvhf.com>
Re: casting for dates
On Wed, 26 Sep 2001, Mitch Vincent wrote:

> Will
>
> SELECT now() - 'nummonths months'::interval ;
>
> work?

Unfortunately no.

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH    email: vev@michvhf.com    http://www.pop4.net
         56K Nationwide Dialup from $16.00/mo at Pop4 Networking
        Online Campground Directory    http://www.camping-usa.com
       Online Giftshop Superstore    http://www.cloudninegifts.com
==========================================================================




Wed, 26 Sep 2001 21:27:49 -0400 (EDT)
Vince Vielhaber <vev@michvhf.com>
Re: casting for dates