Timestamp from table to db

Need to add a timestamp to each calibration entry. Should the timestamp orginate from Ignition or the DB? If ignition, how do I go about adding it to the query?

row = event.source.parent.getComponent(‘Table’).selectedRow
site = tabledata.getValueAt(row, “site”)
cal = tabledata.getValueAt(row, “calibration”)
t_stamp=system.db.dateFormat(now(),“yyyy-MM-dd HH:mm:ss”)

print site, cal

system.db.runPrepUpdate(“INSERT INTO pump_cal (site, calibration, t_stamp) VALUES (?,?,?)”,[site,cal,t_stamp])[/code]

Got it to work using this instead. Is this the correct way of entering the timestamp? Had to differentiate between expressions and scripts in order to get it to work.

tabledata=event.source.parent.getComponent('Table').data row = event.source.parent.getComponent('Table').selectedRow site = tabledata.getValueAt(row, "site") cal = tabledata.getValueAt(row, "calibration") t_stamp= event.source.parent.getComponent('datetime').text print site, cal, t_stamp system.db.runPrepUpdate("INSERT INTO pump_cal (site, calibration,t_stamp) VALUES (?,?,?)",[site,cal,t_stamp])

You’re exactly right. Grabbing a date has to be formatted into a string usable by the db. I think the default datetime string in Ignition includes the weekday when it’s pulled into the script, or some such.

You can also get the current date in scripting like this:from java.util import Date currentDateTime = Date() print currentDateTime