# Convert timestamp to datetime

**URL:** <https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877>\
**Category:** Ignition\
**Created:** [September 20, 2020, 10:11pm UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877 "2020-09-20T22:11:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yfactor](https://avatars.discourse-cdn.com/v4/letter/y/e79b87/32.png) [@Yfactor](https://forum.inductiveautomation.com/u/Yfactor)\
**Post date:** [September 20, 2020, 10:11pm UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877/1 "2020-09-20T22:11:15Z")

</div>

Hi there is there anyway to convert the timestamp to a datetime?  
I have a table with datetime column (sql query) in it and I want to pass the value with payload when click on the table row to a datepicker. It passes the datetime but in a timestamp format…

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/1/41ebce66e91fd7ae26548fb1f3eeb7190c9ff5e4.png)

but I want it to be  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/a/6a90b23a3029a9db0612fe8d5f932e0e9382034b.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 20, 2020, 11:33pm UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877/2 "2020-09-20T23:33:57Z")

</div>

You could do this through scripting I’m sure, but you could also pass the value to a placeholder property (`key` in my example), then bind a property (probably `DateTimeInput.props.value`) to the placeholder and apply a Format transform.

 ![Screen Shot 2020-09-20 at 4.30.27PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e201090769cc57116bc5aab41cd002871392109.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 21, 2020, 5:06am UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877/3 "2020-09-21T05:06:28Z")

</div>

You could also try this:

```auto
from datetime import datetime
return datetime.fromtimestamp(value/1000)

```

where value is the `t_stamp` value. This works for me when attempting to convert a `t_stamp` (big int) column from a MySQL table.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 21, 2020, 3:46pm UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877/4 "2020-09-21T15:46:44Z")

</div>

Eschew Python’s `datetime` - use [`system.date.parse`](https://docs.inductiveautomation.com/display/DOC80/system.date.parse) or [`system.date.fromMillis`](https://docs.inductiveautomation.com/display/DOC80/system.date.fromMillis) to construct Java Date objects.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 21, 2020, 3:51pm UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877/5 "2020-09-21T15:51:21Z")

</div>

Just to add onto @paul-griffith’s response, using Java Date Objects lets you use `system.db.runPrepUpdate` and not have to do any further date/string manipulation, which is very helpful.

---

<div class="post-metadata">

**Author:** ![Yfactor](https://avatars.discourse-cdn.com/v4/letter/y/e79b87/32.png) [@Yfactor](https://forum.inductiveautomation.com/u/Yfactor)\
**Post date:** [September 21, 2020, 8:20pm UTC](https://forum.inductiveautomation.com/t/convert-timestamp-to-datetime/38877/6 "2020-09-21T20:20:27Z")

</div>

> [@cmallonee](#):
>
> datetime.fromtimestamp(value/1000)

Thanks guys for the solutions 👍  
Learnt something new 😃
