FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » determining the difference between two dateTimes
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: determining the difference between two dateTimes [message #174350 is a reply to message #174347] Mon, 06 June 2011 17:58 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 6/6/2011 10:47 AM, 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

Bill,

As you found out, '%i' just gives you the minutes portion of the DateTime.

What if you converted both DateTime objects to timestamps with
getTimestamp()? This will give you the Unix time (seconds since
1/1/1970) and you can subtract those to get the difference. Then a
simple comparison of the seconds will get you the answer you need.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: ONLINE BACKUP IS VERY MUCH ESSENTIAL FOR SECURE YOUR DATA
Next Topic: hai sweety
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 14:22:03 GMT 2024

Total time taken to generate the page: 0.04272 seconds