Re: determining the difference between two dateTimes



bill wrote:
In a scheduling program I need to check to see if there is a conflict between an existing appointment and one that is to be entered. I figured that I would use dateTime::diff

the existing appointment is returned as $row['apptTime'], the appt being tested is $dateTM

$TAptEnd = $dateTM->add(new DateInterval('PT' . $duration .'M'));

$date = new DateTime($row['apptTime']); //dateTime object
of the beginning of the next appt
$diff = $date->diff($TAptEnd,true); //difference between
the beginning of an existing appt and the end of
the testing.

if ($diff->format('%i') <0 ) return 1;

I am running into several problems that suggest that this is not the best way to go about this.

1: if the next appointment is the next day I am getting only the time difference between the appointments, eg 10 min, not the whole time. I would expect the difference to be 24 * 60 + 10, not just the 10.

2: if I need to use the day + hours + minutes it gets really messy.

Suggestions please.

bill
Convert the whole lot using appropriate calls to remove all daylight savings time, into seconds since Jan 1 1970..i.e.. UNIXTIME.

That will give you absolute offset in seconds.

If you are pulling the date times out of MySQL, the call

"set time_zone= '+00:00'"

means that any dates returned for the rest of the session will be UTC.

The the mysql function unix_timestamp(timestamp) will return the number of seconds since Jan 1 1970.

If OTOH you are using some other means than an SQL database to store times, I suggest you scrap them and use that particular way of expressing times and dates. Its very easy to convert from that to the local date in any form you want, using a variety of available functions in PHP and or C or Mysql.. and you have a simple way of calculating date offsets by subtracting two times, and divinding them by 60 - integer or floating point - to get the number of minutes apart.
.



Relevant Pages

  • Hillarys Leading Attribute: Experience
    ... presidential candidacy is her "experience," a virtue which contrasts, ... administration for months as two nominees, in succession, had to withdraw ... she suggested the appointment of Lani Guanier as ... It was Hillary who counseled Bill not to settle the Paula Jones lawsuit even ...
    (soc.retirement)
  • Hillarys Leading Attribute: Experience
    ... presidential candidacy is her "experience," a virtue which contrasts, ... administration for months as two nominees, in succession, had to withdraw ... she suggested the appointment of Lani Guanier as ... It was Hillary who counseled Bill not to settle the Paula Jones lawsuit even ...
    (misc.news.internet.discuss)
  • Re: Retirement
    ... Bill wrote: ... appointment for a diabetic test and and an invitation to the opticians ... for a free eye test once a year plus an invitation to take a retinal ...
    (soc.history.medieval)
  • Re: determining the difference between two dateTimes
    ... On 6/6/2011 10:47 AM, bill wrote: ... between an existing appointment and one that is to be entered. ... the existing appointment is returned as $row['apptTime'], ... What if you converted both DateTime objects to timestamps with getTimestamp? ...
    (comp.lang.php)
  • Re: OT: IL Gov Blagojevich arrested on corruption charges
    ... The local reports here said the prosecutor had to do something now because there is a bill on the Governors desk that would have been significantly altered by the situation. ... He was literally auctioning off the rights to that appointment and had to be stopped before any such 'tainted' appointment could be made. ... Look for the Illinois legislature to very soon a) impeach and remove Blago from office and b) pass a bill with a veto-proof majority to call a special election to fill that open USSenate seat. ...
    (misc.transport.road)