# Issue with Insert Time in SQL

**URL:** <https://forum.inductiveautomation.com/t/issue-with-insert-time-in-sql/22151>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [January 28, 2019, 11:28am UTC](https://forum.inductiveautomation.com/t/issue-with-insert-time-in-sql/22151 "2019-01-28T11:28:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [January 28, 2019, 11:28am UTC](https://forum.inductiveautomation.com/t/issue-with-insert-time-in-sql/22151/1 "2019-01-28T11:28:39Z")

</div>

Hi All,

I know this will be a dumb question but I can’t figure it out.  
I’m reading time from a TAG and insert it into a DB table, but I always get the error `Cannot coerce value 'Mon Jan 28 12:22:22 CET 2019' into type: class [Ljava.lang.Object;`  
The TAG is already in Date format and if I print its type, the console tells me that is “Java.Util:Date”.  
Here it is the script and the output:

 ![Datetime%20Issue](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c9885e2c1ce6bcbec3a649f66a30a1411946a896.png)

Inside the DB Table the column is formatted as “Datetime2”.

Any help on this?

Cheers,

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [January 28, 2019, 11:55am UTC](https://forum.inductiveautomation.com/t/issue-with-insert-time-in-sql/22151/2 "2019-01-28T11:55:20Z")

</div>

Could you please show the complete script? Including how it’s used on the query. And please tell us what DB you’re using too.

At the moment, the screenshot only shows the first part (which is correct), but the second part in comments certainly isn’t correct (the statement isn’t passed to the query, the values aren’t in a list, …)

But at the moment, it’s unclear whether the error comes from problems in the driver, or wrong usage of the functions.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [January 28, 2019, 12:24pm UTC](https://forum.inductiveautomation.com/t/issue-with-insert-time-in-sql/22151/3 "2019-01-28T12:24:21Z")

</div>

A DateTime2 field also requires the milliseconds to be part of the value.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [January 28, 2019, 12:26pm UTC](https://forum.inductiveautomation.com/t/issue-with-insert-time-in-sql/22151/4 "2019-01-28T12:26:22Z")

</div>

Ok, I’m really stupid.  
I forgot to include the statement inside the `system.db.runPrepUpdate()`  
My bad! You know when you are so focused on one thing and you can not see the dumb things 😅  
Thanks for the hint 😉
