It's a question of time ...

This is a discussion on It's a question of time ... within the C Programming forums, part of the General Programming Boards category; Hi guys, i would like to convert a 4 digit number (eg 0824) into a time so that i can ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    12

    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.

    thanks

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    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,
    -michael

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    12
    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?

    thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Code:
    printf("%02d",myInt);
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    12
    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, 03:44 AM
  3. time question.
    By InvariantLoop in forum C Programming
    Replies: 5
    Last Post: 02-01-2005, 01:00 PM
  4. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    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, 03:33 AM

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