+ Reply to Thread
Results 1 to 24 of 24

Converting unusual time format

  1. #1
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Converting unusual time format

    I'm trying to calculate the downtime of some network kit using it's factory tools, but the exported report format for the time period is shown as (for example) "4d 15h 10m" for 4 days, 15 hours and 10 minutes.

    Is it possible to convert this format to either hh:mm or dd:hh:mm, so that I can calculate the SUM totals?

    Alternatively, if it helps, it also shows the start and end date/time of these periods in the following format:
    "Wednesday, September 12, 2012 18:53:17" so it might be possible to work out new downtime periods and use them instead.

    Many thanks in advance,
    Dave.
    Last edited by essee; 09-19-2012 at 05:39 AM.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    With the text:
    "4d 15h 10m"
    in A1, In B1 enter:
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"d ","d"),"h ",":"),"m",":00")
    In C1 enter:
    =--LEFT(B1,FIND("d",B1)-1)+TIMEVALUE(MID(B1,FIND("d",B1)+1,256)) which displays

    4.631944444

    In "summable" format
    Gary's Student

  3. #3
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Converting unusual time format

    Hi essee

    Another version:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Kevin UK; 09-17-2012 at 12:27 PM.

  4. #4
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    @Jakobshavn

    Ah. I fear I may have left out some further information. This works for the dates in that format, but some times are as little as one minute, showing as "1m".

    Is the formula easy to amend for that?

    Thanks for the quick response, you guys on here are, like, magicians when it comes to Excel!

    Kevin, I can't seem to get yours working. Do I need to complete it with any more information?

    Thanks again,
    Dave.
    Last edited by Cutter; 09-18-2012 at 05:18 PM. Reason: Removed whole post quote

  5. #5
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Converting unusual time format

    Hi essee

    See attached file. Hope it helps.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    Hey Kevin, thanks. That's working now, but only for instances of 3 parameters (days, hours, mins) with single digit days. I'm thinking it might be too much to ask for it to work with double or triple digit days (117d 14h 10m), with only hours (14h) with hours & minutes (14h 10m) and only minutes (10m).

    The data looks like this.... (for example)

    4d 15h 10m 4.631944444
    4d 16h 28m 4.686111111
    12m #VALUE!
    5m #VALUE!
    1h 40m #VALUE!
    1h 40m #VALUE!
    58s #VALUE!
    58s #VALUE!
    22h 38m #VALUE!
    59s #VALUE!
    4d 23h 32m 4.980555556
    5m #VALUE!
    6d 11h 53m 6.495138889
    5m #VALUE!
    22d 9h 51m #VALUE!
    22d 9h 51m #VALUE!
    22d 9h 51m #VALUE!
    22d 9h 51m #VALUE!
    22d 9h 51m #VALUE!
    22d 9h 51m #VALUE!
    22d 9h 51m #VALUE!
    6m #VALUE!
    6m #VALUE!
    36d 7h 51m #VALUE!
    36d 7h 51m #VALUE!
    117d 12h 15m #VALUE!

    Oh my God, I've just noticed there are only seconds too. This is going to need some serious thinking.

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

    Re: Converting unusual time format

    I broke out the individual units and then summed them. Let me know if you have any questions. Will this work for you?
    Attached Files Attached Files
    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

  8. #8
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    This small User Defined Function (UDF) should solve your problems. (it will also handle seconds):

    Please Login or Register  to view this content.

    User Defined Functions (UDFs) are very easy to install and use:

    1. ALT-F11 brings up the VBE window
    2. ALT-I
    ALT-M opens a fresh module
    3. paste the stuff in and close the VBE window

    If you save the workbook, the UDF will be saved with it.

    To remove the UDF:
    1. bring up the VBE window as above
    2. clear the code out
    3. close the VBE window
    To use the UDF from Excel:

    =UnTiFo(A1)

    To learn more about macros in general, see:

    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    or

    http://www.cpearson.com/excel/Writin...ionsInVBA.aspx
    for specifics on UDFs

    Here ae some inputs/outputs:


    4d 15h 10m 4.631944444
    4d 15h 10m 4.631944444
    4d 16h 28m 4.686111111
    12m 0.008333333
    5m 0.003472222
    1h 40m 0.069444444
    1h 40m 0.069444444
    58s 0.000671296
    58s 0.000671296
    22h 38m 0.943055556
    59s 0.000682870
    4d 23h 32m 4.980555556
    5m 0.003472222
    6d 11h 53m 6.495138889
    5m 0.003472222
    22d 9h 51m 22.410416667
    22d 9h 51m 22.410416667
    22d 9h 51m 22.410416667
    22d 9h 51m 22.410416667
    22d 9h 51m 22.410416667
    22d 9h 51m 22.410416667
    22d 9h 51m 22.410416667
    6m 0.004166667
    6m 0.004166667
    36d 7h 51m 36.327083333
    36d 7h 51m 36.327083333
    117d 12h 15m 117.510416667
    12s 0.000138889
    0m 86400s 1.000000000

  9. #9
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    You chaps are total geniuses. I'm surprised people don't want to burn you at the stake with such witch craft! Thanks so much. This is my new favourite forum. Everyone so keen to help!

    ChemistB seems to provide the most simple way of doing it, so I'll get cracking with that. I did have to change the Days slightly, as the formula seemed to be missing the days, so I just copied the formula from the others. Thanks to Jakobshavn for the UDF stuff, which I will no doubt be seeing again in the future.

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

    Re: Converting unusual time format

    Glad it's working for you. Days is in Column B.

  11. #11
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    Yes, that's right, I amended it to reflect that, however, the last 3 rows appear to be wrong, even though they follow the same formula/pattern.

    Weird, right?

  12. #12
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    It seems to get to 30days in column A and then reset to 0 days in column F, and repeat that every 30 days.

  13. #13
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    If the formulas work for you, just ignore the VBA suggestion.

  14. #14
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    Quote Originally Posted by Jakobshavn View Post
    If the formulas work for you, just ignore the VBA suggestion.
    I'm going to give that a go tomorrow. It's better to have more options and improve my general Excel knowledge, while I have the time to do so. Thanks!

  15. #15
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    Very Good.........update this post if you require any help.

  16. #16
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    Quote Originally Posted by Jakobshavn View Post
    Very Good.........update this post if you require any help.
    The UDF works lovely. I think I'm going to go with that. Thanks for showing me this function!

  17. #17
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    Thank you for the feedback!

  18. #18
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    Quote Originally Posted by Jakobshavn View Post
    Very Good.........update this post if you require any help.
    Hey Jakobshavn, I've been having a good play with this, but I'm thinking I'd like the results in a usable "dd:hh:mm" or "hhhh:mm" format, instead of decimal hours. Would that be difficult to change?

    Many thanks,
    Dave.

  19. #19
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    All you need to do is change the format. See the attached workbook. Note that for some formats, some values will display incorrect results. See items hi-lighted.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    09-17-2012
    Location
    South Wales, UK
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Converting unusual time format

    Many thanks. I did get to that point, with help from a colleague.

    I guess it's working out the days until it gets to a month. It would be nice to just shows days. I'll do some more searching. Someone else must have seen this problem.

    Thanks again.

  21. #21
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    Have a Great Day!

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

    Re: Converting unusual time format

    I know I'm late to the party but here's a formula solution that should work for up to two digit hours, mins or seconds, but up to 3 digit days, in any combination

    =SUM(MID("00"&B2&"00000",FIND({"d","h","m","s"},B2&"xxxdhms")-{1,0,0,0},{3,2,2,2})/{1,24,1440,86400})
    Audere est facere

  23. #23
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Converting unusual time format

    The only error I see in your formula is for:


    0m 86400s

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

    Re: Converting unusual time format

    I'm assuming that's not a likely input value - as I said my formula works for up to 2 digit hours, mins and seconds (3 for days)

    This formula will return a (text) result like dd:hh:mm:ss, allowing display of days > 31

    =IF(COUNTIF(B2,"*d*"),LEFT(B2,FIND("d",B2)-1),0)&TEXT(SUM(MID(0&B2&"0000",FIND({"h","m","s"},B2&"xxxhms")-1,2)/{24,1440,86400}),":hh:mm:ss")

+ 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