Best way to construct timestamp from elements

I want to construct a timestamp from individual elements (year, month, day, hour, minute, second).
The elements are initially coming from a PLC and then I’m writing into a database.

This script (admittedly with some hard-coded values) appears to work:

[code]from datetime import datetime
dt_y = 2016
dt_m = 1
dt_d = 20
dt_h = 12
dt_mn = 34
dt_s = 56
tstamp=datetime(dt_y, dt_m, dt_d, dt_h, dt_mn, dt_s)

sql = “UPDATE mytable SET t_stamp=? WHERE ID=1”
system.db.runPrepUpdate(sql,[tstamp])[/code]

But is this the best way of doing it?

There’s probably not a “right” answer to this. What you have is certainly acceptable. Since Ignition is built with java and jython has to convert to java objects to move data through the system, I tend to use the corresponding java objects directly. There are various differences, but the same end effect. Somewhat more efficient if needed in big loops.[code]from java.util import Date
dt_y = 2016
dt_m = 1
dt_d = 20
dt_h = 12
dt_mn = 34
dt_s = 56
tstamp=Date(dt_y-1900, dt_m-1, dt_d, dt_h, dt_mn, dt_s)

sql = “UPDATE mytable SET t_stamp=? WHERE ID=1”
system.db.runPrepUpdate(sql,[tstamp])[/code]