converting date and time as text into a usable date / time format in excel

Greg Moulton 0 Reputation points
2024-09-19T16:59:12.1733333+00:00

Want to convert User's image into usable date/time format. Have seen =DATEVALUE(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",100)),100,100))) used to produce date, but did not include time - I need time code to measure duration between 2 entries

Microsoft 365 and Office Excel For business Windows
{count} votes

2 answers

Sort by: Most helpful
  1. Jiajing Hua 18,060 Reputation points Moderator
    2024-09-20T09:06:55.5133333+00:00

    Hi @Greg Moulton

    If you get the time, please check whether my formulas are helpful:For hour number: =-LOOKUP(0,-RIGHT(LEFT(A2,FIND(":",A2)-1),2))

    For minute number: =TRIM(MID(SUBSTITUTE(A2,":",REPT(" ",100)),100,100))

    For second number: =-LOOKUP(0,-LEFT(TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)),2))

    AM or PM: =MID(TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)),FIND(" ",TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)))+1,2)

    (If your time is like DST, MDT with 3 characters, then you may use =LEFT(RIGHT(A2,6),2) instead.)

    User's image

    Then you may combine them with "Time" function (=IF(B9="PM",TIME(B6+12,B7,B8),TIME(B6,B7,B8))), and set the cell format: h:mm:ss.

    User's image

    If you do not list the hour, minute and second numbers, you may try =IF(MID(TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)),FIND(" ",TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)))+1,2)="PM",TIME(-LOOKUP(0,-RIGHT(LEFT(A2,FIND(":",A2)-1),2))+12,TRIM(MID(SUBSTITUTE(A2,":",REPT(" ",100)),100,100)),-LOOKUP(0,-LEFT(TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)),2))),TIME(-LOOKUP(0,-RIGHT(LEFT(A2,FIND(":",A2)-1),2)),TRIM(MID(SUBSTITUTE(A2,":",REPT(" ",100)),100,100)),-LOOKUP(0,-LEFT(TRIM(RIGHT(SUBSTITUTE(A2,":",REPT(" ",100)),100)),2)))).

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. Barry Schwarz 3,746 Reputation points
    2024-09-24T13:46:45.4833333+00:00

    If you isolate the time information in the string, the TIMEVALUE function will convert the text to a numeric time.

    =TIMEVALUE(MID(LEFT(A2,LEN(A2)-3),FIND("at ",A2)+3,100))

    You mentioned that you want to compute time duration. If your time span starts before midnight and ends after, you will need to include the date so that subtracting 11 PM Monday from 1 AM Tuesday will properly result in 2 hours. The DATEVALUE function can be applied the same way.

    =DATEVALUE(MID(LEFT(A2,FIND("at ",A2)-1),FIND(",",A2)+1,100))

    Then you add the two to get a date-time value.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.