pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Ruprecht <chrup999@yahoo.com>
To: p-php <pgsql-php@postgresql.org>
Subject: Re: Date Manipulations
Date: Wed, 11 Jul 2001 12:56:28 -0500
Message-ID: <006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com> (raw)
References: <002101c10a12$bea29660$5dd26383@corp.compucom.com>
	<000d01c10a28$13ac67c0$1a0d040a@Mitch>

Well, what I was trying to do was this:

I need to insert records into a rate table. The table has start and end
dates (fdate, tdate) and there are no gaps in the dates allowable. We have
things like 4/1/2001 - 4/15/2001, the next record _MUST_ have 4/16/2001 as a
start date ... and so on. The last record has 12/31/2999 as an end date
(meaning forever, until the Y3K bug hits, but I don't plan to be in the
programming business by then).
When I insert a record, I have to find at least one other record, either to
determine what my new end date should be (when I insert it before the first
record) or, I need to adjust the end date of an existing record to one day
before my new record's start date.
I do this by:
$OldDate = pg_result( $FindOldRate, 0, 4 );
and
update ... set rate.tdate = ('$NewDate'::date - 1)::date ...

What I found is that I also need to do:
Insert ... values( ('$NewDate'::date + 0)::date ...

the + 0 (as in ZERO) gets me - if I do it this way, it works, if I leave it
off, it complains that it has a bad external representation (or something
like that). But the field has the format "YYYY-MM-DD" ... it just has me
puzzled ... I can manage with the work-around, I just don't understand why,
and I would like to know why (even if this knowledge serves no purpose ;-).

Best regards,
Chris


----- Original Message -----
From: "Mitch Vincent" <mvincent@cablespeed.com>
To: "Chris Ruprecht" <chrup999@yahoo.com>; "p-php"
<pgsql-php@postgresql.org>
Sent: Wednesday, July 11, 2001 11:39 AM
Subject: Re: [PHP] Date Manipulations


> Well, it depends on what you're trying to do :-)
>
> You can add days an arbitrary date in a number of ways , I often let PG
> handle it though (as you are)..
>
> I generally do something like
>
> SELECT ('05-05-2001'::date + '5 days'::interval)
>
> Or something like that if I need X days ahead or behind date Y...
>
> ----- Original Message -----
> From: "Chris Ruprecht" <chrup999@yahoo.com>
> To: "p-php" <pgsql-php@postgresql.org>
> Sent: Wednesday, July 11, 2001 10:06 AM
> Subject: [PHP] Date Manipulations
>
>
> > Hi all,
> >
> > Currently, when working with dates, I use constructs like
> >
> > ('$NewDate'::date + 5)::date
> >
> > this seems a little clumsy to me and I was wondering if there was an
> easier
> > way of doing this.
> >
> > Best regards,
> > Chris
> >
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




view thread (3+ messages)

Message-ID: <006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com>
Permalink:  ../006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com/
Also on:    postgresql.org/message-id/006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: chrup999@yahoo.com
  Subject: Re: Date Manipulations
  In-Reply-To: <006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com>
  References: <002101c10a12$bea29660$5dd26383@corp.compucom.com> <000d01c10a28$13ac67c0$1a0d040a@Mitch> <006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com>

* 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