# Strptime and runPrepUpdate timezone offset

**URL:** <https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [August 27, 2019, 2:54pm UTC](https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801 "2019-08-27T14:54:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [August 27, 2019, 2:54pm UTC](https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801/1 "2019-08-27T14:54:31Z")

</div>

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”)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 27, 2019, 3:24pm UTC](https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801/2 "2019-08-27T15:24:47Z")

</div>

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](https://en.wikipedia.org/wiki/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.

---

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [August 27, 2019, 3:58pm UTC](https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801/3 "2019-08-27T15:58:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 27, 2019, 4:36pm UTC](https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801/4 "2019-08-27T16:36:40Z")

</div>

Ouch. Well, I would suggest moving to [`system.date.parse`](https://docs.inductiveautomation.com/display/DOC80/system.date.parse), 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`](https://docs.inductiveautomation.com/display/DOC80/system.date.format).

---

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [August 27, 2019, 4:57pm UTC](https://forum.inductiveautomation.com/t/strptime-and-runprepupdate-timezone-offset/27801/5 "2019-08-27T16:57:19Z")

</div>

Thanks, that did it.
