HomeGoogle DocsSpreadsheetEPOCHTODATE Function in Google Sheets

EPOCHTODATE Function in Google Sheets

Published on

When you have a Unix epoch timestamp in seconds, milliseconds, or microseconds, you can convert that to a DateTime using the EPOCHTODATE function in Google Sheets.

The converted DateTime (timestamp) will be in UTC. But, you can get the local time by adding a timezone offset.

Most of you are probably here to learn the function for future use.

If that is the case, you may not have a Unix epoch timestamp (also known as Unix time, POSIX time, or Unix timestamp) for testing.

So what we will do here is first convert a given DateTime to Unix epoch timestamps in seconds, milliseconds, and microseconds.

Then use the EPOCHTODATE function to convert them back to our local DateTime. That will be quite interesting, right?

Let’s understand the function and arguments first.

Syntax and Arguments

Syntax of the EPOCHTODATE Function in Google Sheets:

EPOCHTODATE(timestamp, [unit])

Arguments:

Timestamp:- A Unix epoch timestamp.

Unit:- The unit of time (in seconds, milliseconds, or microseconds) in which the timestamp is expressed.

You can leave the unit or input 1 for seconds, 2 for milliseconds, or 3 for microseconds.

How to Use the EPOCHTODATE Function in Google Sheets

As mentioned at the beginning of this tutorial, we would first convert a local timestamp to Unix epoch timestamps.

Then we will use the EPOCHTODATE function to convert them. Here are those steps.

Prerequisites

I have the timestamp (DateTime) 14/02/2023 10:10:15 in the format dd/mm/yyyy hh:mm:ss in cell C3.

Please note that the Unix Time is the seconds since 1st Jan 1970 (Epoch). So, use a date greater than 01/01/1970 for testing.

Also, my timezone (IST) is ahead of GMT by 5:30 Hours. So I’ve used -time(5,30,0) in the formulas below.

You must adjust this parameter based on your GMT offset (use the - operator if it is ahead and the + operator if it is behind).

Here are related two tutorials:

The following formulas in cells D3, D4, and D5 convert the value in C3 to Unix epoch timestamps.

D3 (Unix Epoch Timestamp in Seconds):

=(C3-DATE(1970,1,1)-time(5,30,0))*86400

D4 (Unix Epoch Timestamp in Milliseconds):

=(C3-DATE(1970,1,1)-time(5,30,0))*86400000

D5 (Unix Epoch Timestamp in Microseconds):

=(C3-DATE(1970,1,1)-time(5,30,0))*86400000000

Let’s convert these Unix epoch timestamps to DateTime in UTC using the EPOCHTODATE function in Google Sheets first.

EPOCHTODATE Function to Convert DateTime to UTC

We already have the Unix epoch timestamps in seconds, milliseconds, and microseconds in cell range D3:D5.

In F3:F5, we will use the EPOCHTODATE function to convert them into Universal Time Coordinated (UTC).

EPOCHTODATE Function to Convert DateTime to UTC

F3 Formula:

=EPOCHTODATE(D3,1)

F4 Formula:

=EPOCHTODATE(D4,2)

F5 Formula:

=EPOCHTODATE(D5,3)

EPOCHTODATE Function to Convert DateTime to Local Time

As you can see in the above examples, the results do not match the value in C3.

The reason is the EPOCHTODATE function returns the dates in UTC, and the C3 value is in the local timezone.

EPOCHTODATE Function to Convert DateTime to Local Time

If you want the converted date in your local timezone, you may ± your GMT offset from the returned date.

In my case (my timezone is ahead of GMT by 5:30 Hours), it will be like this:

F3:

=EPOCHTODATE(D3,1)+time(5,30,0)

F4:

=EPOCHTODATE(D4,2)+time(5,30,0)

F5:

=EPOCHTODATE(D5,3)+time(5,30,0)

That’s all about how to use the EPOCHTODATE function in Google Sheets.

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.

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

More like this

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

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.