Thread: It's a question of time ...

  1. #1
    Registered User
    Join Date
    Apr 2006

    Lightbulb It's a question of time ...

    Hi guys,

    i would like to convert a 4 digit number (eg 0824) into a time so that i can find the length of time between two times.
    => so 0824 and 0927 gives 1 hour and 3 minutes

    i have found a function in the time.h library => difftime=(time_t timeB, time_t timeA)
    but im unsure as to how to declare the numbers etc.

    if anyone has any ideas, or good sites for information, i would be very grateful.


  2. #2
    Registered User
    Join Date
    Feb 2006
    since you don't seem to be using seconds you can create a function to convert both times to minutes then subtract the clock out time from the clock in time to get minutes worked.

    ex: 0927 = 567 minutes
    0824 = 504 minutes

    567 - 504 = 63 minutes

    hope that helped,

  3. #3
    Registered User
    Join Date
    Apr 2006
    great - thanks, it now works like that

    but i havent agot a clue how i can display integers with a '0' in front.
    i.e. 8 is displayed as 08

    does any body have an idea?


  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Of course !!! i shudda known that!!!

    Thanks alot anyway, Salem, saved me once again!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  3. time question.
    By InvariantLoop in forum C Programming
    Replies: 5
    Last Post: 02-01-2005, 02:00 PM
  4. Killing someones grandparents
    By nickname_changed in forum A Brief History of
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  5. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 04:33 AM