# SQL Queries and Time Differences

**URL:** <https://forum.inductiveautomation.com/t/sql-queries-and-time-differences/99392>\
**Category:** General Discussion\
**Created:** [December 4, 2024, 2:05am UTC](https://forum.inductiveautomation.com/t/sql-queries-and-time-differences/99392 "2024-12-04T02:05:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [December 4, 2024, 2:05am UTC](https://forum.inductiveautomation.com/t/sql-queries-and-time-differences/99392/1 "2024-12-04T02:05:02Z")

</div>

A particular gateway I'm working with is giving odd results when returning queries that contain a time type. When I make the query in SSMS (this is MS SQL) the times retuned are correct although they have a date component. When the same query is done inside Ignition, either via script of the Query Browser, they are off by one hour (less). The time zone of the gateway is correct and anyway wasn't even aware that SQL datetime or time types were time zone aware.

I do understand that the returned time type is cast into a java Date time so the date is always Jan 1, 1900 which is fine. I'm just perplexed about the time being off and unsure of how to address it. Any help would be appreciated.

Here's an example query:

> SELECT start\_time FROM \_shift WHERE department\_id=? AND shift\_number=?

When issued from Ignition I get: 1900-01-01 06:00:00.000. When done in SSMS I get 07:00:00.0000000

Kurt

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [December 8, 2024, 11:42am UTC](https://forum.inductiveautomation.com/t/sql-queries-and-time-differences/99392/2 "2024-12-08T11:42:08Z")

</div>

> [@SQL Server store datetime object with time zone](https://forum.inductiveautomation.com/t/sql-server-store-datetime-object-with-time-zone/49319/2):
>
> Two suggestions: Don’t use jython’s datetime. Use java.util.Date and related types–that’s what Ignition passes around. Set MS SQL Server to use UTC and the server it runs on to UTC. That is the only way to have flawless date/time/timezone support in Ignition. Java’s datetime type is fundamentally built in milliseconds UTC (including serialization when passed over a network) with conversions to and from local time zones as needed. This allows clients and gateways to work with the same…

> Microsoft SQL has a DATETIME column type that does not store time zone information. It also has a DATETIME2 column type that **does** store the origin timezone.
