Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Epoch time to GMT, UTC, IST

AKPWZ
8 - Asteroid

Hi everyone,

Just wanted to check if we can convert epoch time into different timezones such as GMT, UTC, IST, etc.?

What methods or functions can be used for this conversion?

 

Thank you 

13 REPLIES 13
binuacs
20 - Arcturus
AKPWZ
8 - Asteroid

Hi @binuacs  Thank you for passing along this link.
I looked but didn't find it useful since I'm seeking for something that will allow me to convert epoch unix time to GMT, IST, or any other nation time zone.

 

binuacs
20 - Arcturus

@AKPWZ Can you provide the sample data and expected output?

AKPWZ
8 - Asteroid

Hi @binuacs thank you for your response.
Sharing the details as a screenshot:

1. Sample Data marked with yellow color

2. Output marked with blue color

3. And the expected output marked with green color. 

 

And the formula which I'm using is this: - DateTimeAdd('1970-01-01',[date]/1000, 'Seconds')

But this formula giving me the output marked with blue color, but I'm expecting the output marked with green color.

 

Thank you

 

AKPWZ_0-1685000647670.png

 

binuacs
20 - Arcturus

@AKPWZ @If you add 5.30 hours to your GMT time using the DateTimeAdd() function,which is in blue you will get the result marked in green colour? Right now I’m away from my system, couldn’t provide a workflow 

binuacs
20 - Arcturus

@AKPWZ @The epoch time always convert into GMT, then to convert that into local time you need to add the difference between GMT and local time zone with the result. Since you are in IST time zone you need to add 5.30 hours to the result

binuacs
20 - Arcturus

@AKPWZ DateTimeAdd('1970-01-01',([date]/1000)+19800, 'Seconds'), this should convert to IST format 

AKPWZ
8 - Asteroid

thank you @binuacs I will try this and let you know. 

SeanAdams
17 - Castor
17 - Castor

Hey @AKPWZ 

 

@binuacs is right - unix epoch times are just the number of seconds since a defined starting point, so you can do this with basic date-add of seconds.

However - I would not recommend doing regular old addition of a fixed time difference to change timezones - because from one week to the next the timezone difference between GMT; EST; IST changes (daylight savings etc).

 

So for this - I'd lean on a Python library to make sure you get this right.     Which python library I hear you ask - well I asked Chat GPT:https://chat.openai.com

 

Question: python to change timezone on a date-time to various other timezones - e.g. from GMT to IST; or GMT to EST

Answer:

To change the timezone of a datetime object in Python, you can use the `pytz` library. Here's an example of how to convert a datetime from one timezone to another:

```python
from datetime import datetime
import pytz

# Create a datetime object with the original timezone
original_datetime = datetime.now(pytz.timezone('GMT'))

# Convert the datetime to another timezone
new_timezone = pytz.timezone('IST') # Replace 'IST' with your desired timezone
converted_datetime = original_datetime.astimezone(new_timezone)

# Print the converted datetime
print(converted_datetime)
```

In the example above, the original datetime is created using the GMT timezone. You can replace `'GMT'` with any other valid timezone name, such as `'EST'` for Eastern Standard Time. Similarly, you can replace `'IST'` with the desired timezone, such as `'EST'` for Eastern Standard Time or any other timezone supported by the `pytz` library.

Note: Make sure you have the `pytz` library installed. You can install it using `pip install pytz`.

 

Labels