Convert Unix Timestamp to Local DateTime and Vice Versa

Have you ever come across Unix Time, Unix Timestamp, or Epoch Time in Google Sheets? If so, you might have wondered how to convert Unix Timestamp to local DateTime or vice versa. In this article, I will guide you through the steps to decode and convert Unix Timestamp to local DateTime, as well as the reverse process, in Google Sheets.

Understanding Unix Time

Unix Time refers to the number of seconds since January 1, 1970 (Epoch). It acts as a unique identifier for a particular date or time. To convert Unix Timestamp to local DateTime or vice versa, understanding Unix Time is essential.

To convert a local DateTime to Unix Time, you need to follow these steps:

Step 1: Convert Local DateTime to Unix Time

Let’s start with the formula to convert a local DateTime to Unix Time in Google Sheets. Suppose you have a timestamp in cell A2, such as “13/10/2019 09:54:00”. To convert this timestamp to seconds, you need to use the following formula:

=DATE(1970,1,1)*86400

This formula converts the date “01/01/1970 00:00:00” to seconds. You can replace DATE(1970,1,1) with the corresponding cell reference.

Step 2: Convert Timestamp to Seconds

Now, let’s convert the given timestamp to seconds using the DATE and TIME functions in Google Sheets. In cells C2 and C3, you can use the following formulas:

=DATE(2019,10,13)+TIME(9,54,0)*86400

The first formula converts the timestamp “01/01/1970 00:00:00” to seconds, while the second formula converts the given timestamp to seconds. You can replace DATE(2019,10,13) with the corresponding cell reference.

Step 3: Include the Time Zone Offset

To convert the local DateTime to Unix Time accurately, you must consider the time zone offset. For example, if your time zone is GMT+05:30, you need to convert the five and a half hours to seconds using the TIME function:

=TIME(5,30,0)*86400

Replace the time zone offset with the corresponding cell reference if needed.

Step 4: Final Conversion Formula

To convert the local DateTime to Unix Time, use the following formula:

=A3*86400-B2*86400-B5*86400

This formula subtracts the seconds calculated in Steps 1, 2, and 3 from the given timestamp to get the Unix Time.

Converting Unix Timestamp to Local DateTime

To convert a Unix Timestamp to local DateTime in Google Sheets, follow these steps:

Step 1: Convert Unix Time to DateTime

Suppose you have a Unix Timestamp in cell B3, such as “1570940640”. To convert this Unix Time in seconds to DateTime, divide it by 86400:

=B3/86400

Step 2: Add Epoch DateTime and Time Zone Offset

To get the local DateTime, add the Epoch DateTime (“01/01/1970 00:00:00”) and the time zone offset. If your time zone is GMT+05:30, use the following formula:

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

Replace the time zone offset with the corresponding cell reference if needed.

In conclusion, by following these steps, you can easily convert Unix Timestamp to local DateTime and vice versa in Google Sheets. Experiment with the formulas and apply them to your own data to experience the magic of time conversion!

Check out Crawlan.com for more exciting articles and tutorials on SEO, marketing, and web development.

Related posts