Strptime and runPrepUpdate timezone offset

I have a code that I tested in Ignition 7.9 before our new system was set up and it now has an issue with Ignition 8.03. The simplified code below works fine to put the date into our MS SQL database in Ignition 7.9. When I copied the script to Ignition 8.03, I found that instead of writing the date to the database, it first subtracts the timezone offset and then writes it to the database, hence the date below is written as 08/28/17 04:17:16 instead of 08/28/17 11:17:16. How do you attach the timezone information to the strptime function so that the runPrepUpdate will insert the correct date?

import datetime
t_stamp = datetime.datetime.strptime(“08/28/17 11:17:16”, “%m/%d/%y %H:%M:%S”)
print t_stamp

Query = “INSERT INTO ACT_Header (FileType, TubeNum, t_stamp) Values (?,?,?)”
Values = [“Test2”, “5678”, t_stamp]
system.db.runPrepUpdate(Query, Values, “MTAGS”)

Where is the source date/time coming from? If you can, I would highly suggest avoiding ever working with a date(time) as a string - basically any conversion outside of a full ISO 8601 string is a “lossy” conversion. If you’re working with an Ignition component that handles dates, you should be able to pull the date value out of the component and directly insert it into the DB using runPrepUpdate - no parsing or manipulation required.

1 Like

The date time string is actually coming from a text file that was written by a 20 year old piece of software. That software created paper records using text files. The new software will store the data in a database. I’m using Ignition to be the basis for the new software, but we have to import the text files from the old software for historical data.

Ouch. Well, I would suggest moving to, so that you’re at least working with native Java objects - one less possible complication. You should be able to manually add a timezone to the string to be parsed, then identify it in the placeholder with z/zzzz/Z.

Thanks, that did it.

1 Like