Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 4th, 2007, 9:56 PM   #1
MiKuS
Programmer
 
Join Date: Jun 2007
Posts: 88
Rep Power: 2 MiKuS is on a distinguished road
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?
MiKuS is offline   Reply With Quote
Old Sep 4th, 2007, 10:41 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 4th, 2007, 11:11 PM   #3
MiKuS
Programmer
 
Join Date: Jun 2007
Posts: 88
Rep Power: 2 MiKuS is on a distinguished road
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.
MiKuS is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:35 AM.

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