# Is there a way to convert epoch timestamp to a human readable datetime?

**URL:** <https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700>\
**Category:** Matillion ETL\
**Created:** [April 4, 2022, 5:34pm UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700 "2022-04-04T17:34:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![VVeda](https://sea2.discourse-cdn.com/flex002/user_avatar/matillioncommunity.discourse.group/vveda/32/834_2.png) [@VVeda](https://matillioncommunity.discourse.group/u/VVeda)\
**Post date:** [April 4, 2022, 5:34pm UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/1 "2022-04-04T17:34:35Z")

</div>

My file format has a column that is in epoch format. ex - {"time\_epoch\_sample": 1648612800000}.I'd like to load into Snowflake in a human readable DATETIME format. Any help please?

---

<div class="post-metadata">

**Author:** ![ChrisHastie-InterWorks](https://sea2.discourse-cdn.com/flex002/user_avatar/matillioncommunity.discourse.group/chrishastie-interworks/32/41_2.png) [@ChrisHastie-InterWorks](https://matillioncommunity.discourse.group/u/ChrisHastie-InterWorks)\
**Post date:** [April 5, 2022, 9:13am UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/2 "2022-04-05T09:13:09Z")

</div>

Hey [@VVeda](https://matillioncommunity.discourse.group/u/VVeda)​,

I think your simplest option here would be to use the [TO\_TIMESTAMP](https://docs.snowflake.com/en/sql-reference/functions/to_timestamp.html#to-timestamp-to-timestamp) function in Snowflake. For example:

TO\_TIMESTAMP(1648612800000, 3)

which produces the result:

2022-03-30 04:00:00.000

I hope this helps!

---

<div class="post-metadata">

**Author:** ![VVeda](https://sea2.discourse-cdn.com/flex002/user_avatar/matillioncommunity.discourse.group/vveda/32/834_2.png) [@VVeda](https://matillioncommunity.discourse.group/u/VVeda)\
**Post date:** [April 5, 2022, 5:40pm UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/3 "2022-04-05T17:40:24Z")

</div>

Thanks Chris. That does help. But the bigger issue I have is my file is in .ndjson format with one of the fields in the above mentioned epoch time, which needs to be converted/ or add another column with regular datetime field into the target table.

I was able to use python and convert the file from .ndjson to .csv prior to loading via S3. However, I'm looking if there is a way to just be able to use Matillion and automate this process. Support indicated that I should be able to use a python script component, but I was unsure how to proceed. In case anyone is able to provide solution, I'm attaching a sample file here.

---

<div class="post-metadata">

**Author:** ![PCorb](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@PCorb](https://matillioncommunity.discourse.group/u/PCorb)\
**Post date:** [April 6, 2022, 5:35pm UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/4 "2022-04-06T17:35:36Z")

</div>

@vveda - what i might do (similar to chris' answer without converting json to csv) is land the original data (json) from the file into a temporary table with 1 column of variant datatype, then process the tmp table into the target table converting with snowflake sql.

simulate file loaded into tmp table:

create table x.y.TEST\_VARIANT (TEST\_VARIANT variant)

insert into x.y.TEST\_VARIANT (TEST\_VARIANT)

select parse\_json('{"time\_epoch\_test": 1648612920000, "device": "CHEC.SUB4.RTU4", "substation": "CHEC.SUB4", "institution": "CHEC", "point": "1", "name": "1", "value": 1240.}')

convert timestamp:

select TEST\_VARIANT, TEST\_VARIANT:time\_epoch\_test as time\_epoch\_test, to\_timestamp\_ltz((TEST\_VARIANT:time\_epoch\_test::integer),3) as time\_epoch\_test\_as\_timestamp

from x.y.TEST\_VARIANT

I would use as little python as necessary, in this case none!

---

<div class="post-metadata">

**Author:** ![ChrisHastie-InterWorks](https://sea2.discourse-cdn.com/flex002/user_avatar/matillioncommunity.discourse.group/chrishastie-interworks/32/41_2.png) [@ChrisHastie-InterWorks](https://matillioncommunity.discourse.group/u/ChrisHastie-InterWorks)\
**Post date:** [April 7, 2022, 9:04am UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/5 "2022-04-07T09:04:53Z")

</div>

[@VVeda](https://matillioncommunity.discourse.group/u/VVeda)​ here's a quick demo in Snowflake showing how this could work, starting from the raw string in a single field and ending with the timestamp. I have also attached the SQL I've used, which is similar to [@PCorb](https://matillioncommunity.discourse.group/u/PCorb)​'s

![0694G00000KCKsOQAX_0D74G000006c82OSAQ](https://us1.discourse-cdn.com/flex002/uploads/matillioncommunity/original/1X/f2104cb9da16430c4e37054b88b8299f20aaa0ea.gif)

---

<div class="post-metadata">

**Author:** ![VVeda](https://sea2.discourse-cdn.com/flex002/user_avatar/matillioncommunity.discourse.group/vveda/32/834_2.png) [@VVeda](https://matillioncommunity.discourse.group/u/VVeda)\
**Post date:** [April 7, 2022, 1:32pm UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/6 "2022-04-07T13:32:22Z")

</div>

Thanks a lot for [@PCorb](https://matillioncommunity.discourse.group/u/PCorb)​. Appreciate your response. I'll check it out today.

---

<div class="post-metadata">

**Author:** ![VVeda](https://sea2.discourse-cdn.com/flex002/user_avatar/matillioncommunity.discourse.group/vveda/32/834_2.png) [@VVeda](https://matillioncommunity.discourse.group/u/VVeda)\
**Post date:** [April 7, 2022, 1:49pm UTC](https://matillioncommunity.discourse.group/t/is-there-a-way-to-convert-epoch-timestamp-to-a-human-readable-datetime/1700/7 "2022-04-07T13:49:03Z")

</div>

Thanks a lot for the detailed demo Chris. Really appreciate your response. I'm guessing I can use this sql in the sql component in Matillion and load the target table. Will check it out.

&nbsp;

thanks

Vani
