+ Reply to Thread
Results 1 to 9 of 9

24 hour clock calculating total hours using midnight

  1. #1
    Registered User
    Join Date
    05-28-2010
    Location
    London
    MS-Off Ver
    MS365 (PC) Version 2301
    Posts
    87

    24 hour clock calculating total hours using midnight

    hi,

    I am using a formula to determine how many hours have been worked between times
    using colons
    i.e 14:00 to 16:00

    14:00 is (C8-INT(C8))*24
    16:00 is (D8-INT(D8))*24

    Then I've =D8-C8 in another column to give me a total hours worked

    this works fine but when I get to using 0:00 for midnight the figures go wrong and I get a negative figure

    in the above example I would get -14.00

    how do I combat this please??

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: 24 hour clock calculating total hours using midnight

    try to use this approach

    =MOD(EndTime-StartTime,1)

    Multiply result by 24 if you want to get result as decimal.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: 24 hour clock calculating total hours using midnight

    Try

    =MOD(D8-C8,24)
    Audere est facere

  4. #4
    Registered User
    Join Date
    05-28-2010
    Location
    London
    MS-Off Ver
    MS365 (PC) Version 2301
    Posts
    87

    Re: 24 hour clock calculating total hours using midnight

    Thanks - perhaps I should have given another example

    I've a start time of 19:30 and end time of 0:00

    using

    =MOD(D8-C8,24)

    I get 04:30 hours which is correct in hours and mins but I need it to read 4.5

    end of the day and I am having a bad one - mind gone blank!

    All help gratefully received - if you could

    Thanks

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: 24 hour clock calculating total hours using midnight

    Sorry, I thought you were already converting the times to decimal, If C8 and D8 contain time values then use MOD with divisor or 1 as contaminated says....and then multiply by 24 to get the decimal value, i.e.

    =MOD(D8-C8,1)*24

  6. #6
    Registered User
    Join Date
    05-28-2010
    Location
    London
    MS-Off Ver
    MS365 (PC) Version 2301
    Posts
    87

    Re: 24 hour clock calculating total hours using midnight

    Quote Originally Posted by daddylonglegs View Post
    Sorry, I thought you were already converting the times to decimal, If C8 and D8 contain time values then use MOD with divisor or 1 as contaminated says....and then multiply by 24 to get the decimal value, i.e.

    =MOD(D8-C8,1)*24

    thanks that worked but the bit I don't understand now is how this is affecting an IF formula elsewhere in the sheet

    I've attached what I'm doing

    Row 4 shows that between 14:00 and 16:00 2 hours have been worked and this gives 2 in column G but when you look at column N (which asks it to compare with column the result in column M) it returns the conditional format I've put in i.e. "Error" saying that the 2 in G doesn't match the 2 in N

    However it works for Row 8 perfectly!!

    Does this make sense?
    Attached Files Attached Files

  7. #7
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: 24 hour clock calculating total hours using midnight

    What if you try this n column N

    =IF(ROUND(M5-G5,2)=0,"","Error")

    BTW, real result of M5-G5 is 1.77635683940025E-15 .... which's not equals to zero...)))
    Last edited by contaminated; 09-06-2010 at 11:32 AM.

  8. #8
    Registered User
    Join Date
    05-28-2010
    Location
    London
    MS-Off Ver
    MS365 (PC) Version 2301
    Posts
    87

    Re: 24 hour clock calculating total hours using midnight

    Quote Originally Posted by contaminated View Post
    What if you try this n column N

    =IF(ROUND(M5-G5,2)=0,"","Error")

    BTW, real result of M5-G5 is 1.77635683940025E-15 .... which's not equals to zero...)))
    Brilliant thank you - appreciated!

    and that would explain it!!

    now, how do I mark this one "Solved"

    Cheers

  9. #9
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: 24 hour clock calculating total hours using midnight

    Read forum rules Rule # 9

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1