Unix timestamps in Excel and Google Sheets
Spreadsheets store a date as a count of days, so converting a timestamp is one division and one addition. The result is in UTC until you add your offset.
Timestamp to date
With the timestamp in A1:
=A1/86400+DATE(1970,1,1) seconds
=A1/86400000+DATE(1970,1,1) millisecondsThe cell will show a number such as 45244.92593. Format it as a date and time (Format Cells, Custom, yyyy-mm-dd hh:mm:ss) and 1700000000 becomes 2023-11-14 22:13:20.
It works because a spreadsheet date is the number of days since the end of 1899, with the time as the fraction of a day. There are 86,400 seconds in a day, and DATE(1970,1,1) is day 25,569. The same formulas work in Google Sheets and LibreOffice Calc.
Date to timestamp
=(A1-DATE(1970,1,1))*86400 seconds
=(A1-DATE(1970,1,1))*86400000 milliseconds
=(NOW()-DATE(1970,1,1))*86400 the current time, see the note on time zonesFormat the result cell as a number, not a date. Wrap it in ROUND(…, 0) if you see a stray fraction: times are stored as floating-point fractions of a day and do not always land on a whole second.
Time zones
A spreadsheet date has no time zone. The formulas above treat it as UTC, so adjust by hand:
=A1/86400+DATE(1970,1,1)+TIME(5,30,0) UTC+5:30 (India)
=A1/86400+DATE(1970,1,1)-TIME(5,0,0) UTC-5 (New York in winter)
=(A1-DATE(1970,1,1)+TIME(5,0,0))*86400 a New York winter time back to a timestampA fixed offset is wrong for half the year in places with daylight saving time, and no formula knows the rules. For data that spans a clock change, convert before it reaches the spreadsheet. NOW() returns the local time of the computer (Excel) or of the spreadsheet's time zone setting (Sheets), so (NOW()-DATE(1970,1,1))*86400 is only a true timestamp when that zone is UTC.
Google Sheets: EPOCHTODATE
=EPOCHTODATE(A1) seconds
=EPOCHTODATE(A1, 2) milliseconds
=EPOCHTODATE(A1, 3) microsecondsSheets has a built-in function for this direction. The result is in UTC, not in the spreadsheet's time zone, and still needs a date-time number format. Excel has no equivalent.
Pitfalls
- The cell shows
#####or a huge year: the value is in milliseconds and the formula divides by 86,400. Divide by 86,400,000. - Timestamps imported as text (left-aligned, often from CSV) make the formula return
#VALUE!. UseVALUE(A1)or multiply by 1. - Long numbers lose digits. Excel keeps 15 significant digits, so 16-digit microsecond and 19-digit nanosecond timestamps are rounded as soon as they are typed or imported. Import them as text and cut them down first:
=VALUE(LEFT(A1,10)). - Dates before 1900 cannot be shown by Excel, so negative timestamps earlier than about -2,208,988,800 fail.
- Workbooks using the 1904 date system (an option under Excel's advanced settings, once the default on the Mac) still work, because
DATE(1970,1,1)is counted in the same system.
Questions
What is the Excel formula to convert a Unix timestamp to a date?
=A1/86400+DATE(1970,1,1) for a timestamp in seconds, then format the cell as a date and time. For milliseconds divide by 86400000.
Why is my converted time a few hours off?
The formula gives UTC. Add or subtract your offset, for example +TIME(1,0,0) for UTC+1.
How do I convert a date to epoch in Google Sheets?
=(A1-DATE(1970,1,1))*86400, with the result cell formatted as a plain number.