pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Harald Fuchs <hf0923x@protecting.net>
To: pgsql-sql@postgresql.org
Subject: Re: Date Interval
Date: 06 Dec 2005 18:15:24 +0100
Message-ID: <87k6eixi37.fsf@srv.protecting.net> (raw)
References: <20051206135906.ECA9713E35@spinet.pl>
	<200512061654.jB6Gs5d14178@candle.pha.pa.us>

In article <200512061654.jB6Gs5d14178@candle.pha.pa.us>,
Bruce Momjian <pgman@candle.pha.pa.us> writes:

> Magdalena Komorowska wrote:
>> Hi,
>> I hale a problem with counting interwal and I can't find what to do with
>> this. 
>> I have two fields in the table:
>> Column       |  Type   | Modifiers
>> -----------------+---------+-----------
>> date_in         | date    |
>> interwal_months | numeric |
>> -----------------+---------+-----------
>> 
>> Query
>> SELECT date_in + INTERVAL '3 MONTH' FROM any_table
>> works fine of course. 
>> 
>> However, how to do something like that?
>> SELECT date_in + INTERVAL ' interwal_months MONTH' FROM any_table

> How about this?

> 	test=> CREATE TABLE test(x TEXT);
> 	CREATE TABLE
> 	test=> INSERT INTO test VALUES ('3');
> 	INSERT 0 1
> 	test=> SELECT current_timestamp + cast(x || ' months' AS INTERVAL) FROM
> 	test;
> 	           ?column?
> 	-------------------------------
> 	 2006-03-06 11:53:05.574279-05
> 	(1 row)

Since Magdalena doesn't store the number of months in a string, the
following might be more convenient:

  SELECT date_in + interwal_months * INTERVAL '1 MONTH' FROM any_table




view thread (8+ messages)  latest in thread

Message-ID: <87k6eixi37.fsf@srv.protecting.net>
Permalink:  ../87k6eixi37.fsf@srv.protecting.net/
Also on:    postgresql.org/message-id/87k6eixi37.fsf@srv.protecting.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: hf0923x@protecting.net
  Subject: Re: Date Interval
  In-Reply-To: <87k6eixi37.fsf@srv.protecting.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox