+ Reply to Thread
Results 1 to 16 of 16

Milliseconds missing leading zeroes

  1. #1
    Registered User
    Join Date
    01-03-2016
    Location
    Antwerp Belgium
    MS-Off Ver
    2013
    Posts
    6

    Milliseconds missing leading zeroes

    Hello,

    I have a TXT files which has timestamps with milliseconds. The problem is that all values which are less than three digits show up without leading zeroes. So, for example:

    2019/9/24, 15:02:08.8
    2019/9/24, 15:02:08.9
    2019/9/24, 15:02:08.10
    2019/9/24, 15:02:08.11

    When I try to load the data in excel using h:mm:ss.000 it just appends zeroes to the digits, which is wrong. The problem is compounded by the fact that I also have millisecondd values later on with three digits (i.e. 2019/9/24, 15:02:08.100, 2019/9/24, 15:02:08.101, etc).

    Is there a way for me to load the data and fix the column so that all millisecond values show up correctly?

    Thanks in advance!

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,351

    Re: Milliseconds missing leading zeroes

    Welcome to the forum.

    So how is Excel meant to determine what to do with something that comes through as .800? Should this be seen as .8 or .08 or even .008?

    You are going to need to deal with this issue at source, I fear.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    01-03-2016
    Location
    Antwerp Belgium
    MS-Off Ver
    2013
    Posts
    6

    Re: Milliseconds missing leading zeroes

    Hi,

    Thanks for the quick reply! Anything with 3 digits would keep those three digits. So I guess I'm wondering whether excel can identify where there are only one or two digits, and then add one or two leading zeroes. Not possible?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,351

    Re: Milliseconds missing leading zeroes

    Yes, it's possible, but messy, and the resulting data will be seen as text by Excel, not as a date and time:

    Excel 2016 (Windows) 32 bit
    A
    B
    C
    1
    2019/9/24, 15:02:08.8 2019/9/24, 15:02:08.008
    2
    2019/9/24, 15:02:08.9 2019/9/24, 15:02:08.009
    3
    2019/9/24, 15:02:08.10 2019/9/24, 15:02:08.010
    4
    2019/9/24, 15:02:08.11 2019/9/24, 15:02:08.011
    Sheet: Sheet1

    Excel 2016 (Windows) 32 bit
    C
    1
    =LEFT(A1,FIND(".",A1))&TEXT(MID(A1,FIND(".",A1)+1,3),"000")
    Sheet: Sheet1

  5. #5
    Registered User
    Join Date
    01-03-2016
    Location
    Antwerp Belgium
    MS-Off Ver
    2013
    Posts
    6

    Re: Milliseconds missing leading zeroes

    Alternatively, is there a way I can get excel to just load the numbers as they are?

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,351

    Re: Milliseconds missing leading zeroes

    You can open the .txt file directly in Excel, yes, but of course it comes through as you see it above. You will still need to process it, and Excel will not see it as data and time - it's the wrong format. You'd need to further process each entry for Excel to treat it as such.

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

    Re: Milliseconds missing leading zeroes

    Quote Originally Posted by AliGW View Post
    ... and the resulting data will be seen as text by Excel, not as a date and time ...
    Ali,

    couldn't you multiply your formula by 1 to convert it back to date/time format?

    Pete

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,351

    Re: Milliseconds missing leading zeroes

    I don't know, Pete, could I?

    Answer: Yes! Bingo!!!

    Excel 2016 (Windows) 32 bit
    A
    B
    C
    1
    2019/9/24, 15:02:08.8
    24/09/2019 15:02:08.008
    2
    2019/9/24, 15:02:08.9
    24/09/2019 15:02:08.009
    3
    2019/9/24, 15:02:08.10
    24/09/2019 15:02:08.010
    4
    2019/9/24, 15:02:08.11
    24/09/2019 15:02:08.011
    Sheet: Sheet1

    Excel 2016 (Windows) 32 bit
    C
    1
    =SUBSTITUTE(LEFT(A1,FIND(".",A1))&TEXT(MID(A1,FIND(".",A1)+1,3),"000"),",","")*1
    Sheet: Sheet1

    The cell needs this custom formatting: dd/mm/yyyy hh:mm:ss.000
    Attached Files Attached Files
    Last edited by AliGW; 10-27-2019 at 11:23 AM.

  9. #9
    Registered User
    Join Date
    01-03-2016
    Location
    Antwerp Belgium
    MS-Off Ver
    2013
    Posts
    6

    Re: Milliseconds missing leading zeroes

    Wow, this is great. I'm so excited to try this out, but... Now I have a different problem being able to implement your solution. When I format the cells as text, in order to get the original timestamps, they should up as a number like

    0.626489583
    0.626490741
    0.626491898

    I've no idea why!? Any idea how I can get excel to show the original (erroneous) timestamps?

    Thanks so much for all your help, and on a Sunday no less!!!

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,351

    Re: Milliseconds missing leading zeroes

    Why are you formatting the cells as text? Did you look at my sample file and the last line in that post, which says this:

    The cell needs this custom formatting: dd/mm/yyyy hh:mm:ss.000

  11. #11
    Registered User
    Join Date
    01-03-2016
    Location
    Antwerp Belgium
    MS-Off Ver
    2013
    Posts
    6

    Re: Milliseconds missing leading zeroes

    My problem is that when I try to load my txt file (data>from Text/CSV) it automatically load the data with a format which doesn't show
    the original numbers for that column. If I try to change the formatting of that column to ss.00 or ss.000, it just appends trailing zeroes,
    and if I do ss.0 or ss.00 it also cuts of the third digit of those numbers that have three digits.

    Also, the date and time are automatically loaded into two separate columns (which is how I need them).

    I'm attaching a snippet of the file for your perusal. Thanks so much!
    Attached Files Attached Files

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Milliseconds missing leading zeroes

    When I opened the file (File > Open) with comma and space as separators, the second column formatted (oddly) as mm:ss. When I changed the format, it was fine:

    A
    B
    C
    1
    9/24/2019
    15:02:08.700
    2997.5
    2
    9/24/2019
    15:02:08.800
    2997.5
    3
    9/24/2019
    15:02:08.900
    2997.5
    4
    9/24/2019
    15:02:08.100
    2997.5
    5
    9/24/2019
    15:02:08.110
    2997.5
    6
    9/24/2019
    15:02:08.120
    2997.5
    Entia non sunt multiplicanda sine necessitate

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

    Re: Milliseconds missing leading zeroes

    I think what the OP is saying is that whatever produces the .txt file is doing it wrong. The first few time values in that file should be 15:02:08.007, 15:02:08.008, 15:02:08.009, 15:02:08.010, 15:02:08.012, i.e. for some reason the software that produces the .txt file is removing any leading zeros from the milliseconds part of the time field.

    Pete

  14. #14
    Registered User
    Join Date
    01-03-2016
    Location
    Antwerp Belgium
    MS-Off Ver
    2013
    Posts
    6

    Re: Milliseconds missing leading zeroes

    Pete, that's exactly it!

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Milliseconds missing leading zeroes

    That's unfixable once it's in the text file; x.1 could mean x.001, x.010, or x.100

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,351

    Re: Milliseconds missing leading zeroes

    But we knew this at the outset, which is why I said at first that it would need dealing with at source. Are we going round in circles? What exactly is the issue? I’m lost ...

+ 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. Leading Zeroes in XML
    By MoranCC in forum Excel General
    Replies: 1
    Last Post: 05-16-2019, 10:53 PM
  2. Leading Zeroes in XML
    By MoranCC in forum Excel General
    Replies: 3
    Last Post: 05-08-2019, 05:37 AM
  3. Add zeroes within dates (NOT leading zeroes)
    By anthony19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2012, 04:08 PM
  4. Leading Zeroes & XML
    By jlhart76 in forum Excel General
    Replies: 4
    Last Post: 06-03-2009, 08:23 PM
  5. Keeping Leading Zeroes
    By EmmaG1959 in forum Excel General
    Replies: 2
    Last Post: 04-09-2008, 05:39 AM
  6. [SOLVED] Leading Zeroes
    By Ken in forum Excel General
    Replies: 1
    Last Post: 10-07-2005, 11:05 AM
  7. [SOLVED] No decimals and leading zeroes
    By gcotterl in forum Excel General
    Replies: 2
    Last Post: 04-18-2005, 02:06 AM

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