+ Reply to Thread
Results 1 to 8 of 8

convert a number in time format

  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2013
    Posts
    137

    convert a number in time format

    Hi
    After an exhaustive search here in forum and google, I didn´t find any solution to this issue.

    Here's my problem:

    i received a file with time data in this format:
    003457 - Which means 00h 34m 57s
    012554 - Which means 01h 25m 54s
    035839 - and so on...
    042510
    054439
    063532
    065722
    075211
    075612
    101740
    102817
    105527
    105715

    to convert I used the following formula
    =IF(A1>9999,TIME(LEFT((RIGHT(N2,6)),2),LEFT((RIGHT(N2,4)),2);RIGHT(N2,2)),TIME(0,LEFT((RIGHT(N2,4)),2),RIGHT(N2,2)))
    But it doesn't work in all conversions
    003457 - 00h 34m 57s - YES
    012554 - 01h 25m 54s - WRONG 12h 25m 54s
    035839 - 03h 58m 39s - WRONG 11H 58m 39s
    042510 - 04h 25m 10s - WRONG 18H 25m 10s
    054439 - 05h 44m 39s - WRONG 06H 44m 39s
    063532 - 06h 35m 32s - WRONG 15H 35m 32s
    065722 - 06h 57m 22s - WRONG 17H 57m 22s
    075211 - 07h 52m 11s - WRONG 03H 52m 11s
    075612 - 07h 56m 12s - WRONG 03H 56m 12s
    101740 - 10h 17m 40s - YES
    102817 - 10h 28m 17s - YES
    105527 - 10h 55m 27s - YES
    105715 - 10h 57m 15s - YES

    So, what am I doing wrong?
    Thanks very much in advance.

    Ioncila

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: convert a number in time format

    Try

    =TEXT(--N2;"00\:00\:00")

  3. #3
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2013
    Posts
    137

    Re: convert a number in time format

    Hi Jason
    PERFECT!
    AND TOO MUCH SIMPLIER.

    Thank You Very much
    Ioncila

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: convert a number in time format

    first, you are missing a 9 in your condition (99999) and then you must set the hour to the first digit in case A1<99999 like in the folloowing formula:
    Please Login or Register  to view this content.
    I don't know why you were referencing A1 and N2 so I wrote the formula as if the time was in cell A1.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: convert a number in time format

    Following your logic of hhmmss, I am unsure why you say these are wrong?
    012554 - 01h 25m 54s - WRONG 12h 25m 54s
    035839 - 03h 58m 39s - WRONG 11H 58m 39s
    042510 - 04h 25m 10s - WRONG 18H 25m 10s
    what tells you that is 12 hours and not 1?
    what tells you that is 11 hrs and not 3
    etc?
    what am I missing here?

    (not that it really matters, but) if your "numbers" start with a leading 0, and that is actually IN the cell, then those cells contain text, not a number

    I used this...
    A
    B
    2
    003457 12:34:57 AM
    3
    012554 1:25:54 AM
    4
    035839 3:58:39 AM
    5
    042510 4:25:10 AM
    6
    054439 5:44:39 AM
    7
    063532 6:35:32 AM
    8
    065722 6:57:22 AM
    9
    075211 7:52:11 AM
    10
    075612 7:56:12 AM
    11
    101740 10:17:40 AM
    12
    102817 10:28:17 AM
    13
    105527 10:55:27 AM
    14
    105715 10:57:15 AM

    B2=TIME(LEFT(A2,2),MID(A2,3,2),RIGHT(A2,2))
    copied down

    @ Jason, your formula gives a text answer, that is not really time, although it looks like it is. As a text, copy that to all the "numbers" provided, and try and sun the total
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: convert a number in time format

    Quote Originally Posted by FDibbins View Post
    @ Jason, your formula gives a text answer, that is not really time, although it looks like it is. As a text, copy that to all the "numbers" provided, and try and sun the total
    I was aware of that, Ford, given that the source data appeared to be in text format, I left the output the same. The formula can be coerced to numeric values with a double unary.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: convert a number in time format

    OK, just making an observation, and you are correct with the -- to convert

  8. #8
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2013
    Posts
    137

    Re: convert a number in time format

    Hi
    First, I thank you all for the feedback and discussion about my issue.
    But, for the record, I didn't put my problem in a correct way, although Jason got it to the point I needed.

    The data to convert (ex, 003457) means the time completation of a task (in this case, 34m 57s), and not a timestamp.

    Jason's suggestion did answer to my doubt. What I didn't refer is that I added a small change to formula to get numeric results:
    =VALUE(TEXT(--N2;"00\:00\:00"))

    Once again
    Thank you very much

    Ioncila

+ 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. [SOLVED] Convert number to time format
    By suedavies in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-16-2015, 08:40 AM
  2. convert number to date time format
    By sensation in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-09-2013, 05:16 AM
  3. [SOLVED] Convert number format to time format
    By bgates in forum Excel General
    Replies: 3
    Last Post: 11-29-2013, 09:04 AM
  4. Convert date and time in serial number format to text format
    By nda13112 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-11-2013, 02:45 PM
  5. Excel: How to convert time format into number format that can be added?
    By Frances Jones in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-17-2012, 04:10 PM
  6. Convert decimal number to time format
    By browny in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-06-2007, 02:44 PM
  7. convert number to time format?
    By JLHORMAN in forum Excel General
    Replies: 1
    Last Post: 05-26-2005, 01:38 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