+ Reply to Thread
Results 1 to 11 of 11

Convert decimal to days/hours/mins/secs

  1. #1
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    373

    Convert decimal to days/hours/mins/secs

    Afternoon all,

    I was messing around with a simple countdown timer and need a little help converting a decimal into a format of #days, #hours, #minutes and #seconds.

    Cell A1 has target to countdown to 4/14/2010 12:00:00 AM
    Cell A2 contains =NOW()
    Cell A3 contains =A1-A2 with the result being 69.4021441 with the amount of decimal places varying depending on when it is refreshed.

    I'd Like the result in A3 to read something like "There are 69 days, XX hours, XX minutes and XX seconds until event"

    The help is always appreciated
    Last edited by scaffdog845; 02-03-2010 at 04:05 PM.
    Click here to read the Forum Rules
    Whatever it is in life you decide to go after, go after with great ferocity.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Convert decimal to days/hours/mins/secs

    One way possibly?

    =INT(A1-A2)&" days, "&TEXT(A1-A2,"h ")&"hours, "&TEXT(A1-A2,"m ")&"minutes and "&TEXT(A1-A2,"s ")&"seconds until event"
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Convert decimal to days/hours/mins/secs

    Without using helper cells, and really not getting into Excel today, this should work:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Convert decimal to days/hours/mins/secs

    NBVC, when using yours, the minutes value doesn't seem to change from 3. As of now, 2:05:15pm it should read 54.

    All the rest seems correct though.

    Note: I think it has to do with the "m" being considered "month" instead of "minute"..

  5. #5
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    373

    Re: Convert decimal to days/hours/mins/secs

    Both replys work great. Thanks guys

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Convert decimal to days/hours/mins/secs

    Actually, Paul is right... mine doesn't work for the minutes portion...

    This one should:
    Please Login or Register  to view this content.
    But I am sure it can be done more efficiently... correct daddylonglegs?

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

    Re: Convert decimal to days/hours/mins/secs

    Quote Originally Posted by NBVC View Post
    But I am sure it can be done more efficiently... correct daddylonglegs?
    You've pretty much cracked it, I think, NBVC. Only thing I'd say is you can use MINUTE function for the minute part, i.e.

    ="There are "& INT(A1-A2)&" days, "&TEXT(A1-A2,"h ")&"hours, "&MINUTE(A1-A2)&" minutes and "&TEXT(A1-A2,"s ")&"seconds until the event"

    If you wanted to you could also use HOUR and SECOND in the same way

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Convert decimal to days/hours/mins/secs

    Ah yes! Very good. Thanks daddylonglegs, these time/date formulas always mess me up

    For consistency then... better formula would be...

    ="There are "& INT(A1-A2)&" days, "&HOUR(A1-A2)&" hours, "&MINUTE(A1-A2)&" minutes and "&SECOND(A1-A2)&" seconds until the event"

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Convert decimal to days/hours/mins/secs

    I think I win "The most difficult way to do things" award for today. Anyone care to second my nomination?


  10. #10
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    373

    Re: Convert decimal to days/hours/mins/secs

    Quote Originally Posted by Paul View Post
    I think I win "The most difficult way to do things" award for today. Anyone care to second my nomination?

    Your formula may be a bit longer than the other suggestions; however, when they are all entered in a spreadsheet together and the F9 key is held in your formula seems to be updating 1/2 - 1 second faster. Not sure if you can take that as a consolation prize???

    Thanks all for the help!

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

    Re: Convert decimal to days/hours/mins/secs

    One more version.....you could accommodate hours/mins/secs all in one TEXT function like this

    ="There are "&INT(A1-A2)&" days, "&TEXT(A1-A2,"h"" hours, ""m"" minutes and ""s"" seconds""")&" until the event"

+ 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