Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Time Mathematics (http://www.programmingforums.org/showthread.php?t=13911)

MiKuS Sep 4th, 2007 9:56 PM

Time Mathematics
 
I'm currently doing some work with an appointment script and trying to generate some reports with custom code, i'm having trouble with the mathematics involved.

Here is my problem;
The duration of an event is stored in minutes, now lets say an event goes for 2 hours (120 minutes) i can just divide this by 60 and get my answer, but lets say
the duration is 150 minutes, 2.5 hours how would i convert this to 2 hours and 30 minutes?

Another thing i'm having trouble with is adding on to times, so.. lets say theres an appointment at 23:00 and the duration is 210 minutes (3.5 hours) the end time would be 02:30 how do i mathematically add 3 and 30 minutes to this time without it resulting in being 2630?

DaWei Sep 4th, 2007 10:41 PM

Investigate the modulus operator. Also, you might have a look at the PHP manual regarding time functions.

MiKuS Sep 4th, 2007 11:11 PM

Cheers for the reply, still playing with modulo, so far i have(pseudo code):

150 in hours and minutes:

150/60=2.5 = 2 (round down with floor())
then 1:
50 % 60 = 30

two hours and thirty minutes.

now to work out hours.

edit:
OK thanks, i've sussed it out now. i don't know why i didn't think to use modulo, i guess this is all in the process of becomming a programmer.


All times are GMT -5. The time now is 1:03 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC