Problems with datetime

Hello,
I am struggling through my first Ignition project and have a problem which I somehow can't get to grips with.

I call an MSSQL stored procedure from a script. I read a label.text which contains a German time string, e.g. 10.04.2025 10:00:00. I convert this into a Date object. When I pass this Date object to the StoredProcedure as a timestamp, something always adds an hour to it, which corresponds to the current deviation from UTC, then 2 hours from March 30th. If I pass it as a string to the stored procedure and convert it in the SQL server then it works perfectly. Is there a way to use the datetime conversion without this phenomenon?

My script code:

eventId = self.view.custom.selectedEventId
itemId = self.view.custom.selectedItemId
planStart = self.parent.getChild("columnStartDateTime").getChild("label").props.text
planStart = converter.dateTimeConverter(planStart)
	
call = system.db.createSProcCall("dbo.sp_U_Schedule", "ProdAppDB")
	
call.registerInParam("orderNumber", system.db.NVARCHAR,eventId)
call.registerInParam("equipmentId", system.db.BIGINT,itemId)
call.registerInParam("planstart", system.db.TIMESTAMP,planStart)
call.registerOutParam("responseMessage", system.db.NVARCHAR)
call.registerOutParam("responseCode", system.db.INTEGER)
system.db.execSProcCall(call)

My dateTimeConverter:

def dateTimeConverter(stringToTime):
	import datetime
	responseDateTime = datetime.datetime.strptime(stringToTime , '%d.%m.%Y %H:%M:%S')
	return responseDateTime

Thanks for your support

1 Like

MS SQL Server datetime data types are not timezone-aware. If you cannot use datetime2, run your Ignition gateway and your SQL Server in UTC (both servers) to avoid these kinds of problems.

(Whatever else you do, do not use jython's datetime module. Use Ignition's system.date.* functions or java's native date/time types.)

1 Like

Thank you for your support. Neither Java nor Python are my normal programming languages, I come completely from the .NET language area and there are relatively simple functions to turn a string into a DateTime format. Why should I not use the Jython datetime module? It is shown everywhere in the forums. What Java alternatives are there that I can simply use in the script?

The built-in system.date.* functions:

system.date.parse will easily transform a string into a datetime object.

1 Like

Thank you for your support. It works :+1: