# Date Time and Locale with SQL

**URL:** <https://forum.inductiveautomation.com/t/date-time-and-locale-with-sql/37980>\
**Category:** Ignition\
**Tags:** database, ignition80\
**Created:** [August 21, 2020, 5:42pm UTC](https://forum.inductiveautomation.com/t/date-time-and-locale-with-sql/37980 "2020-08-21T17:42:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [August 21, 2020, 5:42pm UTC](https://forum.inductiveautomation.com/t/date-time-and-locale-with-sql/37980/1 "2020-08-21T17:42:20Z")

</div>

EDIT : It works when I try with prepUpdate as below,

```auto
from java.util import Calendar
query = "UPDATE myTable SET date_created = ? WHERE id = 1"
arg = [cal.getTime()]
system.db.runUpdateQuery(query, arg)

```

But, still looking a way without Prep Query.

Hello There,  
We have a Ignition server in French Locale. I am trying to write update queries from Ignition with scripting (I must do this way).

Since, it gave me an errors I tried different ways as below with script console:

**1.**

```auto
query = "UPDATE myTable SET date_created ='2020-08-21 00:00:00' WHERE id = 1"
system.db.runQuery(query)

```

**2.**

```auto
query = "UPDATE myTable SET date_created ='08-21-2020 00:00:00' WHERE id = 1"
system.db.runQuery(query)

```

**3.**

```auto
from java.util import Calendar
cal = Calendar.getInstance()
query = "UPDATE myTable SET date_created ='%s' WHERE id = 1"%(cal.getTime())
system.db.runQuery(query)

```

But, all of them throws different exceptions rejecting to convert the date into JDBC compatible format.

How do I write dateTime to SQL with scripting ?

The Date Format we have working for servers in North America is : `'yyyy-MM-dd HH:mm:ss'`

Thanks so much in advance

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 21, 2020, 6:02pm UTC](https://forum.inductiveautomation.com/t/date-time-and-locale-with-sql/37980/2 "2020-08-21T18:02:57Z")

</div>

> [@kaushik.shah](#):
>
> But, still looking a way without Prep Query.

Don't. Use the Prep Query or a Named Query. It is almost impossible to handle locales and timezones properly in all cases when using timestamps in string form. If you are converting to/from strings, you are screwing up.
