+ Reply to Thread
Results 1 to 10 of 10

Formula converting hours into working days showing error with specific number of hours

  1. #1
    Registered User
    Join Date
    03-08-2018
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016, Office 365
    Posts
    33

    Formula converting hours into working days showing error with specific number of hours

    I have a spreadsheet that includes a "converter" where the user can enter the length of their work day and their leave entitlement in hours, which Excel then displays in work days, hours and minutes. As I'm just about ready to launch the spreadsheet on colleagues, I thought I'd just do some final checks and double-check the converter with different lengths of work day and leave entitlements...and discovered a problem. The formula works with all permutations of day lengths and leave entitlements, except for one - which is rather unfortunate because it just happens to be the most common working day length and leave entitlement!!

    This is the formula I'm using: =IFERROR(INT($I10/I$8)&" days "&TEXT($I10-INT($I10/I$8)*I$8,"hh:mm"),"ERROR")

    Cell I8 is the length of the work day in hh:mm and I10 is where the number of hours are entered, again in the format hh:mm.

    The only values I'm getting an error with are with a day length of '7:24' and the number of hours '185:00'. It should show a result of 25 days, 00:00

    With 180 hours it works fine, with 181:00, 182:00, 183:00, 184:00....186:00, 187:00, 188:00... All work fine, except with 185:00! 185:00 does work with other day lengths though. I can't for the life of me work out why this particular combination of numbers is causing an error. If anyone can shed any light on why it's exhibiting this strange behaviour with the 7:24/185:00 combo, I'd be most grateful.
    Attached Files Attached Files

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Formula converting hours into working days showing error with specific number of hours

    rounding related -- and XL can't show negative time (the 185:00 will generate a -0.000000000000001)

    given you don't need to worry about subtraction I would be inclined to just wrap a MAX, i.e.

    MAX(0,$I10-INT($I$10/I$8)*I$8)

  3. #3
    Registered User
    Join Date
    07-02-2013
    Location
    Cheshire
    MS-Off Ver
    Office Professional 2007
    Posts
    79

    Re: Formula converting hours into working days showing error with specific number of hours

    Hi there. Your problem is arising because of the way excel handles numbers. When storing decimal numbers (as you are aware, date/times are actually stored as fractions of a day) there are some fractions of a day that cannot be stored precisely (e.g. 6a.m. is 0.25 - a quarter of a day, but 8a.m. (a third of a day) is stored as 0.333333 recurring, and is therefore subject to a very small discrepancy when non-precise decimal values are used. In your case, you can fix this by introducing a very small addition to the sum in your formula like this:
    Please Login or Register  to view this content.
    Try it and see.

  4. #4
    Registered User
    Join Date
    03-08-2018
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016, Office 365
    Posts
    33

    Re: Formula converting hours into working days showing error with specific number of hours

    Thank you both for such speedy responses, and they work perfectly. I've just tried both, and no more errors with either! Thanks again.

  5. #5
    Registered User
    Join Date
    07-02-2013
    Location
    Cheshire
    MS-Off Ver
    Office Professional 2007
    Posts
    79

    Re: Formula converting hours into working days showing error with specific number of hours

    You're welcome and thanks for the feedback.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,719

    Re: Formula converting hours into working days showing error with specific number of hours

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Registered User
    Join Date
    03-08-2018
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016, Office 365
    Posts
    33

    Re: Formula converting hours into working days showing error with specific number of hours

    Okay, so I thought I'd got this working until one of my colleagues messaged me to say that his leave card isn't working properly and isn't showing the right number of days of leave he has remaining. Having corrected the rounding problem, as above, I suspected that he'd possibly just entered a number incorrectly somewhere, but when I took a look at his leave card, it is indeed showing the number of days remaining incorrectly.

    It's working correctly until about half the way down the column, where something strange has started to happen, and it appears to be a rounding problem again. I'm using the same formula:

    Please Login or Register  to view this content.
    His standard working day is 7:24. Formula works fine for several entries, but then, rather than showing the remaining number of days as "7 days 00:00" for example, it's showing the number of remaining days as "6 days 07:24".

    It's like saying that the time is 10:60 rather than 11:00.

    I've checked all the formulas again to check I've not mis-copied anything, and all the formulas look to be fine, and I think it's a rounding problem, but I've no idea why it only kicks in part way down the column, or what the fix is.

    Could anyone advise please?

  8. #8
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Formula converting hours into working days showing error with specific number of hours

    without a file to see it's hard to be sure but you could, perhaps, try to employ MROUND - e.g.

    MAX(0,MROUND($K30-INT($K30/O$15)*O$15,1/86400))

  9. #9
    Registered User
    Join Date
    03-08-2018
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016, Office 365
    Posts
    33

    Re: Formula converting hours into working days showing error with specific number of hours

    Unfortunately that hasn't worked - it just showed many of the values in that column as 'ERROR', but left the results that had been displaying incorrectly exactly the same.

    I've attached my latest test version of the file. The column in question is Column L, the 'Annual Leave Remaining (Days)' column. (The leave card shows leave as both hours and days, as full-time employees get their leave entitlement in days, whereas part-time staff get their leave entitlement in hours. This way I can use the same leave card for both)

    I've highlighted the two results displaying incorrectly in red, but when I tried adding more entries to the list, they too are displaying incorrectly.
    Attached Files Attached Files

  10. #10
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Formula converting hours into working days showing error with specific number of hours

    try

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    need to round the INT element to get correct days.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2018, 01:46 AM
  2. [SOLVED] Converting high amount of hours into days, hours, mins
    By SnowBrian in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 11-05-2018, 07:55 PM
  3. Converting Total Hours to Business Hours/Days
    By Fadooshy in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-27-2015, 12:26 PM
  4. Replies: 1
    Last Post: 04-13-2013, 05:19 AM
  5. Converting days hours minutes to hours
    By namip in forum Excel General
    Replies: 7
    Last Post: 07-10-2011, 02:00 PM
  6. Converting hours to 8 hour days, 31 day limit? Formula blows up at 256 hours..
    By krfarmer in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-25-2010, 05:21 AM
  7. [SOLVED] Problem converting Hours to Days, Hours, Minutes
    By Zyzzx in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-24-2005, 12:05 PM

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