+ Reply to Thread
Results 1 to 11 of 11

Trying to convert time to minutes -- sometimes includes days and sometimes does not

  1. #1
    Registered User
    Join Date
    08-24-2012
    Location
    Hudson, NH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Trying to convert a time value into minutes. It can be in the format of 1:11:11 or 11:11:11 (hours minutes seconds). Or it can be in the format of 1.11:11:11 (days, hours, minutes seconds).

    If no hour, this one works:

    = IF(HOUR(G6)>0,HOUR(G6)*60+MINUTE(G6), MINUTE(G6)))

    This works if there are hours

    =(LEFT(G19,FIND(".",G19)-1))*1440+(MID(G19,FIND(":",G19)-2,2))*60+MID(G19,FIND(":",G19)+1,2)

    But I can't come up with something that works for either case

    Any ideas?
    Thank you

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,787

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    You should be able to do it like this:

    =IF(ISNUMBER(FIND(".",G6)),LEFT(G6,FIND(".",G6)-1))*1440+RIGHT(G6,LEN(G6)-FIND(".",G6))*1440,G6*1440)

    Hope this helps.

    Pete

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    or try

    =IF(ISNUMBER(Find(".",G6)), (LEFT(G19,FIND(".",G19)-1))*1440+(MID(G6,FIND(":",G6)-2,2))*60+MID(G6,FIND(":",G6)+1,2), HOUR(G6)*60+MINUTE(G6))

    Not sure why you had the IF statement on the first formula as HOUR(G6) will resolve to 0 and should not be an issue
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

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

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Try this

    =ROUND(IFERROR(G6*1,MID(G6,FIND(".",G6)+1,9)+LEFT(G6,FIND(".",G6)-1))*1440,0)
    Audere est facere

  5. #5
    Registered User
    Join Date
    08-24-2012
    Location
    Hudson, NH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    This returns "false"

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

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Which one?

  7. #7
    Registered User
    Join Date
    08-24-2012
    Location
    Hudson, NH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Here are some of the values from my spreadsheet:

    0:00:08 -- should convert to 0 minutes
    1:13:37 -- should convert to 73 minutes
    20:06:43 -- should convert to 1206 minutes
    1.18:47:55 -- should convert to 2567

    this formula
    =(LEFT(G19,FIND(".",G19)-1))*1440+(MID(G19,FIND(":",G19)-2,2))*60+MID(G19,FIND(":",G19)+1,2)
    will work for the values containing hours but fails if value has no hours

    thanks everyone for trying to help me!

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

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Quote Originally Posted by SueC View Post
    ....will work for the values containing hours but fails if value has no hours...
    Don't you mean days?

    My suggestion almost gets those values but I rounded to the nearest minute, you seem to be rounding down so try this variation

    =INT(IFERROR(G6*1,MID(G6,FIND(".",G6)+1,9)+LEFT(G6,FIND(".",G6)-1))*1440)

  9. #9
    Registered User
    Join Date
    08-24-2012
    Location
    Hudson, NH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Sorry, first time using Forum. But soo happy I found you all! Petes did not work, Chemist returned false, daddylonglegs returned wrong number of minutes. But thanks again for trying. My previous post has a litte more data. Hope I am being clear enough and not confusing everyone.

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,787

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    This one works with all 4 of your examples:

    =ROUNDDOWN(IF(ISNUMBER(G6),G6*1440,LEFT(G6,FIND(".",G6)-1)*1440+RIGHT(G6,LEN(G6)-FIND(".",G6))*1440),0)

    Hope this helps.

    Pete

  11. #11
    Registered User
    Join Date
    08-24-2012
    Location
    Hudson, NH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Trying to convert time to minutes -- sometimes includes days and sometimes does not

    Two great but different solutions from Pete_UK and daddylonglegs. Thank you so much for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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