39

I have Excel documents containing Unix epoch timestamps from a Java application. I'd like to see what they translate to and represent them as human readable dates inside of Excel.

For example, the following long: 1362161251894 should evaluate to something readable like: 01 Mar 2013 11:07:31,894

I'm assuming I can create a formula for this, but I'm not sure how. Thanks!

6 Answers 6

47

Yes, you can create a formula to do this for you. Java and Unix/Linux count the number of milliseconds since 1/1/1970 while Microsoft Excel does it starting on 1/1/1900 for Windows and 1/1/1904 for Mac OS X. You would just need to do the following to convert:

For GMT time on Windows

=((x/1000)/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1900"))

For GMT time on Mac OS X

=((x/1000)/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1904"))

For local time on Windows (replace t with your current offset from GMT)

=(((x/1000)-(t*3600))/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1900"))

For local time on Mac OS X (replace t with your current offset from GMT)

=(((x/1000)-(t*3600))/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1904"))

In your specific case it looks like you are in a Mountain Time (GMT offset of 7). So if I paste your value given of 1362161251894 in a new Excel spreadsheet in cell A1 and then paste the following formula, I get a result of 41333.46356, which if I then tell Excel to format as a Date (press ctrl+1 on the cell) is: 2/28/13 11:07 AM

=(((A1/1000)-(7*3600))/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1900"))
7
  • 3
    for me on Excel for Mac 2011, it works when I leave off - DATEVALUE("1-1-1904")
    – rymo
    Jul 30, 2014 at 19:44
  • 4
    I read this too quickly and didn't realize this was for milliseconds. If your timestamp is in seconds, be sure to remove the /1000 after x. Mar 10, 2016 at 3:31
  • 2
    Strange. Why would 1485190688881 convert to 1/22 instead of 1/23? Based on a five-hour offset.
    – KDP
    Jan 23, 2017 at 20:12
  • 1
    @rymo There is no need for the formula to take into account how Excel's host system starts counting dates. Excel expresses DATEVALUE as whole numbered days and fractional time, so DATEVALUE("1-1-1904") on Mac would subtract 1 day off of the result, which is not what the OP wants AFAIK.
    – mysteryegg
    Feb 8, 2017 at 20:22
  • I noticed the same thing as @KDP -- my time of day is correct, but the day (date) is reported as one day sooner than it should be (i.e., reports 6/21 when it should be 6/22). What's causing this and how do I "fix" it? Thanks! Dec 19, 2018 at 17:30
20

This seems to be answered here,

=(A1/86400)+25569

1
  • 11
    This works if you convert from milliseconds to seconds on your epoch time-stamp. To make it work correctly for milliseconds, you should do: =(A1/86400000)+25569 and remember that this doesn't take into account timezone.
    – 11101101b
    Mar 1, 2013 at 20:11
5

Epoch time was provided in milliseconds (1523060201838). User is looking to Convert for NY Time Zone (GMT -04:00 or DST -14400).

Cell A1 on Excel has the 13 digit value epoch time.

((A1/1000)-14400)/86400 + 25569

converts to 4/6/18 8:16 PM (after you format cell as Date).

1
  • This way works every time in Excel 2016. +1. Thanks, mate! [Also, a note to others: replace 14400 with 3600*x, where x is your offset from GMT. In this example, EST is GMT -4, and 3600*4 is 14400.] Dec 19, 2018 at 17:31
3

Try

=(A2/86400)+DATE(1970,1,1)+TIME(5,30,0)

it will help for local timing like India is GMT + 5:30.

2

I have found that the easiest formulas to remember and read are these:

Convert from Unix/Epoch timestamp to date in Excel (assuming timestamp is in A2):

=(A2/86400)+DATE(1970,1,1)

This will generate the GMT Excel time value. You then need to set the format for the cell to one of the date formats, or create your own custom format. I tend to use either:

dd-mmm-yy                --> gives 05-Oct-18
dd-mmm-yyyy hh:mm:ss     --> gives 05-Oct-2018 09:45:12

Convert from date to Epoch timestamp (assuming date is in A2):

=(A2-DATE(1970,1,1))*86400

I have found that this page is pretty helpful: Extendoffice excel-timestamp-to-date

Note: If you need to adjust to local time from GMT (New York as an example), add the difference at the end. The following show a -5 hour offset.

=(A2/86400)+DATE(1970,1,1)+(-5/24)
0

Excel expresses days as whole values and times as fractional values. Therefore, if the epoch time was provided in milliseconds since 1-1-1970 from UNIX, then we want to divide by the number of milliseconds in a year and add Excel's representation of 1-1-1970 to provide the human readable UTC time. If your value is in cell A1, then Excel would need:

=A1/86400/1000+DATEVALUE("1-1-1970")

Note you can drop the /1000 if your epoch time was in seconds rather than milliseconds. To convert to local time, where 't' is your local UTC offset (remember to use a negative value if you have a negative UTC offset), you can add/subtract the UTC offset:

=A1/86400/1000+DATEVALUE("1-1-1970")+t/24

Note that your UTC offset may vary based on whether daylight saving time is observed in your location, making this an incomplete solution for showing local times throughout the year in a single spreadsheet.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.