Name Query Datetime

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

	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:

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.

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)']),
	   '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:

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?

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

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 :confused:

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

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