+ Reply to Thread
Results 1 to 6 of 6

Including leading zeros in a time function

  1. #1
    Registered User
    Join Date
    07-09-2015
    Location
    London, England
    MS-Off Ver
    Excel for Mac 2011, Version 14.2.5
    Posts
    2

    Including leading zeros in a time function

    Hi all,

    I am trying to convert time values from an external source into an Excel friendly format.
    I currently have this:
    192546
    182106
    etc
    I had an issue with 24 clock times because of leading zeros, eg: 00:00:03. I fixed this by changing the cell format to Custom, 000000.
    I am now trying to use a formula: =TIME(LEFT(AD2,2),MID(AD2,3,2),RIGHT(AD2,2)) where AD2 contains the times, however whenever it comes across a time with leading zeros it returns the wrong times. See picture and attached spreadsheet example.
    Screen Shot 2015-07-09 at 11.53.35.png
    Is there anyway I can alter the formula to include leading zeros in the calculation?
    Bonus: Is there anyway of combining all of those formulas (in pic and spreadsheet) into one super formula?

    Many thanks in advance!
    Chakyt
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Including leading zeros in a time function

    Formatting just changes the way value is displayed. So instead of AD2 in your formula use TEXT(AD2,"000000")
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    07-09-2015
    Location
    London, England
    MS-Off Ver
    Excel for Mac 2011, Version 14.2.5
    Posts
    2

    Re: Including leading zeros in a time function

    Wow! Thank you!
    Is there anyway to combine the two formulas in that example spreadsheet? The DATE and the TIME functions?
    I've tried but it screws up the formatting and gives the result as eg: 42060 0.964907407407407.
    The formula I tried was:
    =DATE(LEFT(B12,4),MID(B12,5,2),RIGHT(B12,2))&" "&TIME(LEFT(TEXT(C12,"000000"),2),MID(TEXT(C12,"000000"),3,2),RIGHT(TEXT(C12,"000000"),2))

    Thank you!

  4. #4
    Forum Contributor
    Join Date
    01-28-2014
    Location
    Turkey
    MS-Off Ver
    Excel 2013
    Posts
    159

    Re: Including leading zeros in a time function

    Or

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Including leading zeros in a time function

    You had originaly
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Why now you try to join D6 and E6 with
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ?
    Not tested, but this shall do (in row 12):
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    last Text was deleted, because always two rightmost digits will give you seconds no matter if it's 5 or 6 digits total.

  6. #6
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Including leading zeros in a time function

    E6=TEXT(C6,"00\:00\:00")
    OR
    E6=TEXT(C6,"00\:00\:00")+0

    l Learned this from someone in this forum
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

+ 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. VBA function to remove hypens, spaces, leading zeros
    By ssjody in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-07-2014, 08:22 AM
  2. [SOLVED] Using Mid function along with leading zeros
    By alcorp in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-08-2014, 01:54 PM
  3. returning first 10 characters of a number including leading zeros'
    By SusanDoyle in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-30-2013, 07:47 AM
  4. Right Function not working to add leading zeros
    By anthony19 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-14-2012, 05:40 PM
  5. Remove leading zeros from a function
    By elbmag in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-19-2007, 01:27 AM

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