Thread: Working out time duration

  1. #1
    Registered User
    Join Date
    Mar 2009

    Working out time duration

    Hi. I'm trying to create a program that will give the duration between two different times. The times are read in from a text file and are in the form "9:00", "11:00", "15:30", "17:00", etc. I am trying to work out how I'd do this.

    The only thing I can think of is making the time an int, but that would cause problems due to the : in the middle of the number. Is there a way to remove the : when reading in the text file, and then add it back in before giving the output? Because if the two times were 9:00 and 11:00, by completing 1100 - 900, I could get 200, which with the : added back in would give 2:00. The only problem I forsee is when the number of minutes is not 0, because 1100 - 930 would give 170, not 130.

    If anyone can make sense of my rambling and give me a hand, it would be much appreciated. Thanks in advance!

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    RING 0
    Well a computer doesn't store times as "12:30" in a string. Check out ctime (time.h) - C++ Reference, there are some functions here for finding the differences between time. Also look into how it stores time as it is much more efficient then storing strings of time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 02:43 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM
  3. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 01:57 PM
  4. Checking parts of a structure
    By DocDroopy in forum C Programming
    Replies: 11
    Last Post: 08-05-2002, 07:45 AM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM