Re: Date Manipulations - Mailing list pgsql-php
From | Chris Ruprecht |
---|---|
Subject | Re: Date Manipulations |
Date | |
Msg-id | 006a01c10a32$cf3cdec0$5dd26383@corp.compucom.com Whole thread Raw |
In response to | Date Manipulations ("Chris Ruprecht" <chrup999@yahoo.com>) |
List | pgsql-php |
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