Convert Unix Timestamp to Local DateTime and Vice Versa in Google Sheets

Published on

This tutorial describes decoding or converting a Unix Timestamp to local DateTime in Google Sheets. For this purpose, Sheets offers a dedicated function called EPOCHTODATE.

In addition to the above how-to, I will explain how to convert a local DateTime to Unix Time, which is the reverse of the process described above.

I know many of you are familiar with or have heard of the terms Unix Time, Unix Timestamp, or Epoch Time. Essentially, all these refer to a 10-digit encoded UTC Date/DateTime.

Understanding Unix Time is crucial for writing a formula that converts Unix Timestamp to local DateTime or vice versa in Google Sheets.

Unix Time represents the seconds elapsed since 1st January 1970 (Epoch). As you may know, a standard day (in UTC) comprises 86,400 seconds (24 hours * 60 minutes * 60 seconds). These seconds play a vital role in the Unix Timestamp to local DateTime conversion formula in Google Sheets.

First, let’s outline the steps to convert a Local DateTime to Unix Time.

Converting Local DateTime to Unix Time in Google Sheets

To convert a local DateTime (Timestamp) in cell A2 to Unix Time, follow these steps in Google Sheets:

Example: A2 contains 13/10/2019 09:54:00

Step 1: Timestamps to Seconds

Convert the DateTime to the number of seconds by multiplying A2 by 86400, like this:

=A2*86400

This formula in cell B2 will return 3780122040.

In cell A3, enter 1/1/1970 00:00:00 and convert this to seconds by multiplying A3 by 86400:

=A3*86400

This formula in cell B3 will return 2209161600.

Convert Timestamp to Seconds in Google Sheets

You might think that subtracting the seconds (B2-B3) will give you the Unix Epoch Time of the DateTime in A2, since Unix Time is the number of seconds since Epoch (1/1/1970 00:00:00). However, there’s an additional parameter to consider.

To accurately convert the local DateTime, consider the time zone. If the time in A2 is UTC, then using =B2-B3 will convert the Timestamp to Unix Time. If not, determine your local time zone offset.

Step 2: Unix Time Conversion from Local DateTime

For instance, if the time in A2 is GMT+05:30 (India Standard Time), meaning five and a half hours ahead of UTC:

In cell A4, enter 5:30 (adjust this based on your local time zone).

In cell B4, use the following formula to convert the time zone offset to seconds:

=TO_PURE_NUMBER(A4*86400)

This will convert 5:30 to 19800 seconds.

GMT Offsets in Google Sheets

Step 3: Converting Local DateTime to Unix Time

Now, with the GMT Offset in seconds (cell B4), you can convert the local DateTime to Unix Time:

=B2-B3-B4

So the Unix Time corresponds to the DateTime in cell A2, i.e., 13/10/2019 09:54:00, will be 1570940640.

Generic Formula:

In short, you can follow the below generic formula to convert a timestamp to Epoch Time in Google Sheets.

(DateTime-Epoch-GMT)*86400

Note: If your timezone is GMT-, use the generic formula as:

(DateTime-Epoch+GMT)*86400

In our example, you can use the formula as:

=(A2-A3-A4)*86400
Converting local DateTime to Unix Time in Google Sheets

or

=(A2-DATE(1970, 1, 1)-TIME(5, 30, 0))*86400

Converting Unix Timestamp to Local DateTime in Google Sheets

Once you’ve learned the conversion above, the reverse process—converting Unix Timestamp to local DateTime—is straightforward.

Here, the Unix Timestamp to convert to local DateTime is in cell A5, which is 1570940640.

First, convert the 10-digit Unix Time in seconds to DateTime by dividing Unix Time by 86400:

=A5/86400

Then add Epoch Date Time and GMT to this DateTime:

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

Please note, if your timezone is GMT-, adjust the formula accordingly by subtracting the TIME(hr, min, sec).

With the new EPOCHTODATE function, you can replace the above formula with =EPOCHTODATE(A5) + TIME(5, 30, 0).

Convert Unix Timestamp to Local DateTime in Google Sheets

I hope this helps you understand how to convert Unix Timestamp to local DateTime and vice versa in Google Sheets.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.