![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jun 2007
Posts: 88
Rep Power: 2
![]() |
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? |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Investigate the modulus operator. Also, you might have a look at the PHP manual regarding time functions.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jun 2007
Posts: 88
Rep Power: 2
![]() |
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. Last edited by MiKuS; Sep 4th, 2007 at 11:43 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| put method, main and member access specifiers separately | cairo | C++ | 9 | Jul 5th, 2007 11:28 PM |
| way to make a function execute at time 'x' | badbasser98 | C++ | 10 | Apr 5th, 2006 7:14 AM |
| checking file existing time to time, in the same time program do other operation | myName | C++ | 3 | Mar 13th, 2006 8:39 PM |
| Time | ChronicCode | Java | 2 | Aug 11th, 2005 2:22 PM |
| C# Pilot Program | Haz | Existing Project Development | 9 | May 2nd, 2005 9:27 AM |