klm123
klm123

Reputation: 12865

How to convert javascript date like 2020-01-06T17:11:58.643Z to date time in excel?

I have a javascript dates in an excel table, it looks like this: 2020-01-06T17:11:58.643Z
I want to convert it [using Excel only] to a readable date and time format, i.e. something like this: 2020-01-06 18:11:58. Preferably it should be given for a specific Timezone [CET], i.e. one needs to add one hour.

Are there default Excel functions for that? All I can find are functions for converting between different date formats, which are used in different countries.

Upvotes: 0

Views: 208

Answers (1)

Porcupine911
Porcupine911

Reputation: 928

As far as a native formula to convert from your javascript notation I don't believe there is one, but here's an inelegant, brute force method with formulas that gets the job done:

=(DATEVALUE(LEFT(A1,10)) + TIMEVALUE(MID(A1,12,8)) + 1/24)

For those finding this question through a search, Excel stores dates and times as numbers. The date is a serial integer representing the number of days since 31 Dec 1899 (1 Jan 1900 is the value "1"). Time is a decimal from 0.0-0.99999..., where zero is midnight and .99999 being just before midnight the folliwing night. You can join the two together DDDDD.TTTTT. For example, I wrote this at 43841.14.

To walk through the formula I wrote above, The DATEVALUE() formula converts a date from text to Excel's numeric date. The LEFT() formula provides the 10 left-most characters. The TIMEVALUE() formula creates a decimal value for time. The MID() formula takes 8 characters starting from the 12th. I then add the two together to make one single value holding a date and time together. One hour can be represented as one twenty-fourth of one day hence the 1/24 above.

This assumes your input is always formatted the same and you are always adding one hour. You can use a custom cell format of yyyy-mm-dd hh:mm:ss to give the output you request.

(Comment converted to answer since nobody else provided any improvements.)

Upvotes: 1

Related Questions