+ Reply to Thread
Results 1 to 13 of 13

Calculating Time difference where time format includes millisecond

  1. #1
    Registered User
    Join Date
    05-10-2015
    Location
    Ann Arbor
    MS-Off Ver
    M365
    Posts
    83

    Calculating Time difference where time format includes millisecond

    I have a system generated data where the time format includes milliseconds , example 08/10/2023 11:35:02:286. I need only the time. I want to create two columns with start and end times with a third column calculating the difference (in seconds). So far I used 'text to column' to separate the time from the date, however when i tried to calculate the difference using a simple minus operation it returned #VALUE. Any ideas on how I could get this to work would be much appreciated. Many thanks.

  2. #2
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Time difference where time format includes millisecond

    Please replace in the time the last ":" with ".". So: 08/10/2023 11:35:02.286

    If that does not work, please upload a sample workbook (via Go Advanced and Manange Attachments) with the error.
    Last edited by HansDouwe; 10-10-2023 at 09:21 AM.

  3. #3
    Registered User
    Join Date
    05-10-2015
    Location
    Ann Arbor
    MS-Off Ver
    M365
    Posts
    83

    Re: Calculating Time difference where time format includes millisecond

    Thanks HansDouwe. . Just tried a sample 12:28:48.500 - 12:28:48.487 = 1.50463E-07. This is much improved for me. However, how do I reduce the result to at lest 2 decimal places? I'm also thinking how simple is it to add "." between the second and millisecond for all the times in an array.

  4. #4
    Registered User
    Join Date
    05-10-2015
    Location
    Ann Arbor
    MS-Off Ver
    M365
    Posts
    83

    Re: Calculating Time difference where time format includes millisecond

    I multiplied the results by 86400 that return 0.013 secs. which more like the result I'm after. Left with finding a way to add "." between the second and millisecond for all the times in an array.

  5. #5
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Time difference where time format includes millisecond

    Please upload a sample workbook (via Go Advanced and Manange Attachments) with manually added the expected results of the formula.

  6. #6
    Registered User
    Join Date
    05-10-2015
    Location
    Ann Arbor
    MS-Off Ver
    M365
    Posts
    83

    Re: Calculating Time difference where time format includes millisecond

    Sample worksheet attached. Thanks
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,436

    Re: Calculating Time difference where time format includes millisecond

    The SUBSTITUTE() function should be able to handle that task. =SUBSTITUTE(date_time_text,":",".",3). Carefully note the use of the 3 in the optional 4th argument that tells SUBSTITUTE() which instance of the old_text to replace. (SUBSTITUTE() help file describing the behavior of the optional 4th argument: https://support.microsoft.com/en-us/...rs=en-us&ad=us ).

    Another observation: The value of 1.5E-7 value is correct in units of days elapsed. You can use number formatting like [mm]:ss.000 or [s].000 or whatever number format code makes sense to you to display as elapsed seconds or elapsed minutes:seconds or whatever, while leaving the underlying cell value as decimal days. When you multiply by 86400, you are converting days to decimal seconds, but you can no longer use Excel's built in sexagesimal "hour:minute:second" time/number formatting. This decision is entirely up to you.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,436

    Re: Calculating Time difference where time format includes millisecond

    In your sample file, I:

    1) convert time stamp text to date/time serial number. In O4, I enter =VALUE(SUBSTITUTE(B4,":",".",3)) [copy/paste/fill into O4:P8].
    2) time difference is a simple subtraction . In Q4 =P4-O4 formatted as [s].000 [copy/paste/fill into Q4:Q8]
    3) If I want to convert to an actual decimal seconds value, I convert the "days" value to decimal seconds. =CONVERT(Q4,"day","sec") or =Q4*86400. I find that the CONVERT() function helps me remember what I am doing, so I find it easier in the long run to use.

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Time difference where time format includes millisecond

    Here are 2 different solutions without changing the format of time start and time end.

    Solution 1: Please try and copy down and format cells as a number with 2 decimals:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Solution 2: Please try and copy down and custom format the cells as [s].00:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by HansDouwe; 10-10-2023 at 11:55 AM.

  10. #10
    Registered User
    Join Date
    05-10-2015
    Location
    Ann Arbor
    MS-Off Ver
    M365
    Posts
    83

    Re: Calculating Time difference where time format includes millisecond

    Awesome!!! Thanks Both. Really made my day. You've provided me with several brilliant solutions. Thanks a lot..

  11. #11
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Calculating Time difference where time format includes millisecond

    This formula takes care of days and Time up to milliseconds.
    In D4 copied down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  12. #12
    Registered User
    Join Date
    05-10-2015
    Location
    Ann Arbor
    MS-Off Ver
    M365
    Posts
    83

    Re: Calculating Time difference where time format includes millisecond

    Many thanks for your solution. Much appreciated.How do I amend your formula if I want to display the time difference in seconds/minute/Hour number or decimal?

  13. #13
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Time difference where time format includes millisecond

    Please show an example of what exactly it should look like?

+ 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 text to time format millisecond
    By herukuncahyono in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-19-2022, 07:50 AM
  2. Formula for calculating difference in 24 hour time format
    By kjattan1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-28-2021, 07:11 AM
  3. Formula for calculating difference in 24 hour time format
    By kjattan1 in forum Hello..Introduce yourself
    Replies: 0
    Last Post: 10-27-2021, 07:02 PM
  4. Replies: 3
    Last Post: 08-12-2017, 01:48 AM
  5. [SOLVED] Time in Time format and text foramt - Finding the Hours difference
    By thilag in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-19-2013, 07:14 AM
  6. Calculating time difference between two days capturing the overnight time.
    By Monica_La in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-08-2007, 11:22 AM
  7. Replies: 2
    Last Post: 06-16-2006, 01:15 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