7

I'm wondering how to convert a timestamp to a date in Excel.

JavaScript timestamp:

1486812409161

Unix timestamp

1486812409

What Excel function / formula can convert to something like:

2/11/2017 11:26 AM (or any human readable date)

I did see this answer, but I can't get this to work for me (on Mac OS X / Excel 2011).

When I create a new cell and set it's value to the following formula:

= (MsValueCellReference / 86400000) + DATE(1970,1,1)

The result is: 41315.47696

5
  • 4
    silly question, but... did you format that cell as a date? Commented Sep 13, 2017 at 15:08
  • I believe Excel stores its dates as number of days since January 1, 1900. Commented Sep 13, 2017 at 15:09
  • Well I'll be damned. Formatting as a date works. If you write a formal answer, I'll accept. Commented Sep 13, 2017 at 15:10
  • @TimBiegeleisen Yeah, unless you tick on "Use 1904 date system" in File > Options > Advanced > When calculating this workbook. Which, in my experience, then fixes whatever problem you changed it for, while newly breaking everything else and ultimately not being worth the hassle. :P Commented Sep 13, 2017 at 15:14
  • @underscore_d ... or the fact that Excel skips a day in the first leap after 1900 (I think). Commented Sep 13, 2017 at 15:15

2 Answers 2

8

I am using the current formula =(<javascriptTimestamp>)/(1000*60*60*24)+25569 and then formatting the cell with dd/mm/yyyy hh:mm:ss.

To explain the terms in the formula, the Javascript timestamp has milliseconds which accounts for the 1000. There are 60*60*24 seconds in one day.

Finally, Excel dates start on Jan 1 1900, and Javascript starts on Jan 1 1970. There are 25569 days between Jan 1 1900 and Jan 1 1970.

Sign up to request clarification or add additional context in comments.

Comments

5

Excel is pretty happy to interconvert between dates and numbers, as you noticed. However, afaict, it can't always guess correctly which of the two you want to see.

So, to ensure that a value is rendered as a date, you'd need to open the Format Cells dialog, go to the first tab Number, and set the cell's format Category to one of the Date types.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.