# Name Query Datetime

**URL:** <https://forum.inductiveautomation.com/t/name-query-datetime/52354>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [October 26, 2021, 3:35pm UTC](https://forum.inductiveautomation.com/t/name-query-datetime/52354 "2021-10-26T15:35:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kfoldesi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kfoldesi/32/11327_2.png) [@Kfoldesi](https://forum.inductiveautomation.com/u/Kfoldesi)\
**Post date:** [October 26, 2021, 3:35pm UTC](https://forum.inductiveautomation.com/t/name-query-datetime/52354/1 "2021-10-26T15:35:43Z")

</div>

The times are getting changed when stored to MS SQL.  
I’m reading a time stamp out of a Siemens PLC (array of bytes). And converting it with datetime.datetime

```auto
	import datetime
	logger = system.util.getLogger("MyLogger")
	logger.warn('SiemensDate Hour:' + str(h))
	return datetime.datetime(y,m,d,h,i,s,0)

---Logger reported: SiemensDate Hour:16

```

and this bit of code in the calling subroutine printed this:

```auto
MyFunc.MsgBox('GateWay/TagChange/GetBatchData/Script: MyTime = 
MyFunc.SiemensDate ' + str(MyTime)

---Logger reported: 2021-10-25 16:52:51

```

Point being, I’m getting the time correct from the PLC. However, when running the Named Query they are getting changed.

```auto
params = {'id':BTblID,
	   'Start_inHg': MyData['VacuumCheckStart(inHg)'],
	   'Stop_inHg': MyData['VacuumCheckStop(inHg)'],
	   'StartTStamp': MyFunc.SiemensDate(MyData['BatchStart(Time)']),
	   'CoolTStamp' : MyFunc.SiemensDate(MyData['CoolStart(Time)']),
	   'StopTStamp': MyFunc.SiemensDate(MyData['BatchStop(Time)']),
	   'Start_inHgTStamp':MyFunc.SiemensDate(MyData['VacuumCheckStart(Time)']),
	   'Stop_inHgTStamp': MyFunc.SiemensDate(MyData['VacuumCheckStop(Time)']),
	   'HeatSetStartTStamp': MyFunc.SiemensDate(MyData['HeatSetStart(Time)'])}
	BTbl = system.db.runNamedQuery('AN75/UpdateBatchTbl',params)
	MyFunc.MsgBox('GateWay/TagChange/GetBatchData/Script:' + str(params))

---Logger reported: GateWay/TagChange/GetBatchData/Script:{'StartTStamp': 
datetime.datetime(2021,10, 25, 16, 52, 51), 'Start_inHgTStamp': datetime.
datetime(2021, 10, 25, 16, 51, 21), 'Start_inHg': -29.20303, 'Stop_inHgTStamp': 
datetime.datetime(2021, 10, 25, 16, 52, 21), 'HeatSetStartTStamp': datetime.
datetime(2021, 10, 25, 16, 53, 47), 'Stop_inHg': -29.179539, 'id': 31, 'StopTStamp': 
datetime.datetime(2021, 10, 25, 17, 15, 10), 'CoolTStamp': datetime.datetime
(2021, 10, 25, 17, 0, 27)}

```

The Named Query in question:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/18c735c578b9c2e17e2f7d6ce618344f1b5a8dbb.png)

This is a Trace from SQL Server Profiler. But what is being sent to SQL is using datetime2 declaration, and has been converted to UTC. Can I turn this off? Or do I need to convert times to local time w/every select statement? - is there a function for that?

```auto
exec sp_executesql N'UPDATE [dbo].[V1BatchTbl]
   SET [Start_inHg] = @P0
      ,[Stop_inHg] = @P1
      ,[StartTStamp] = @P2
      ,[CoolTStamp] = @P3
      ,[StopTStamp] = @P4
      ,[Start_inHgTStamp] = @P5
      ,[Stop_inHgTStamp] = @P6
      ,[HeatSetStartTStamp] = @P7
 WHERE id = @P8
 ',N'@P0 float,@P1 float,
@P2 datetime2,@P3 datetime2,@P4 datetime2,
@P5 datetime2,@P6 datetime2,@P7 datetime2,
@P8 int',-29.203029632568359,
-29.179538726806641,'2021-10-25 12:52:51','2021-10-25 13:00:27',
'2021-10-25 13:15:10','2021-10-25 12:51:21','2021-10-25 12:52:21',
'2021-10-25 12:53:47',31

```

---

<div class="post-metadata">

**Author:** ![Kfoldesi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kfoldesi/32/11327_2.png) [@Kfoldesi](https://forum.inductiveautomation.com/u/Kfoldesi)\
**Post date:** [October 26, 2021, 5:58pm UTC](https://forum.inductiveautomation.com/t/name-query-datetime/52354/2 "2021-10-26T17:58:00Z")

</div>

Also, if the Named Query is trying to change datetime’s to UTC. It should be adding the four hours. Right?  
I’m so confused 😕

---

<div class="post-metadata">

**Author:** ![awaege1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awaege1/32/28922_2.png) [@awaege1](https://forum.inductiveautomation.com/u/awaege1)\
**Post date:** [October 26, 2021, 8:22pm UTC](https://forum.inductiveautomation.com/t/name-query-datetime/52354/3 "2021-10-26T20:22:56Z")

</div>

I have had issues using the datetime python functions when doing this before. Have you tried using the built-in ignition system.date functions instead?

---

<div class="post-metadata">

**Author:** ![Kfoldesi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kfoldesi/32/11327_2.png) [@Kfoldesi](https://forum.inductiveautomation.com/u/Kfoldesi)\
**Post date:** [October 27, 2021, 1:47pm UTC](https://forum.inductiveautomation.com/t/name-query-datetime/52354/4 "2021-10-27T13:47:15Z")

</div>

No date functions for TZinfo. and not sure how to import packages that come installed for Python. However, my solution was to not use the DateTime field in Named Queries. Changed them all to String. Working fine now.  
You do have to convert the data to str() when passing into the Named Query - or it will modify the hours of the time stamp, before passing it to SQL
