Working out time duration

This is a discussion on Working out time duration within the C++ Programming forums, part of the General Programming Boards category; Hi. I'm trying to create a program that will give the duration between two different times. The times are read ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    12

    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
    Location
    RING 0
    Posts
    507
    Well a computer doesn't store times as "12:30"...as 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, 01:43 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21