# Abnormally datetime timezone change when inserting to database

**URL:** <https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542>\
**Category:** Ignition\
**Tags:** database, ignition81, scripting\
**Created:** [February 12, 2024, 8:15am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542 "2024-02-12T08:15:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_G](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jorge\_G](https://forum.inductiveautomation.com/u/Jorge_G)\
**Post date:** [February 12, 2024, 8:15am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/1 "2024-02-12T08:15:16Z")

</div>

Hi! I'm having some trouble when inserting a datetime into database. I'm running a runPrepStatement over an insert query and when i log the data i'm persisting it appears to be OK, but, when its persisted timezone seems to change. I've setted project timezone to different timezones and nothing changes, neither the timezone of the project nor the timezone of the persisted date. I've tried to force select bringing the date at time zone 'utc' and this crashes... I assume the best way is to store data in utc but no idea of how can i do this if project propperties does nothing and its hard to import third party libraries such as pytz so i can "play" with timezones on python code.  
Regards, Jorge

EDIT: The problem was ignition doesn not work well with python datetimes because of milliseconds. I tried using system.date.now() instead of datetime.now() and now all works fine with sql server datetime column type.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 12, 2024, 8:27am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/2 "2024-02-12T08:27:18Z")

</div>

i would store it as timestamp  
[https://docs.inductiveautomation.com/display/DOC81/system.date.toMillis](https://docs.inductiveautomation.com/display/DOC81/system.date.toMillis)

---

<div class="post-metadata">

**Author:** ![Jorge\_G](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jorge\_G](https://forum.inductiveautomation.com/u/Jorge_G)\
**Post date:** [February 13, 2024, 8:04am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/3 "2024-02-13T08:04:15Z")

</div>

I'm working with sqlserver, so, you mean create a column as bigint and storing date in millis? Sounds well i'll try

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 13, 2024, 8:41am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/4 "2024-02-13T08:41:55Z")

</div>

no nono sql has timestamp columns too right? It looks like a big number, but its a timestamp

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [February 13, 2024, 10:18am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/5 "2024-02-13T10:18:27Z")

</div>

sql server's timestamp is... not a datetime data type. The naming is non-standard. It was used for row versioning, but they introduced `rowversion` to avoid the confusion. Don't use timestamps with sql server.

What the type of your column ?

For reference, here are sql server's date and time data types:

> **[Data types (Transact-SQL) - SQL Server](https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16#date-and-time)**
>
> This article provides a summary of the different data types available in SQL Server.

---

<div class="post-metadata">

**Author:** ![Jorge\_G](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jorge\_G](https://forum.inductiveautomation.com/u/Jorge_G)\
**Post date:** [February 13, 2024, 11:41am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/6 "2024-02-13T11:41:43Z")

</div>

But, as I'm not storing values previous to 1970 then i assume bigint is also a good choice

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 13, 2024, 11:51am UTC](https://forum.inductiveautomation.com/t/abnormally-datetime-timezone-change-when-inserting-to-database/85542/7 "2024-02-13T11:51:56Z")

</div>

timestamp is for values after 1970
