# Timestamp from table to db

**URL:** <https://forum.inductiveautomation.com/t/timestamp-from-table-to-db/3654>\
**Category:** Ignition\
**Created:** [November 23, 2011, 11:14pm UTC](https://forum.inductiveautomation.com/t/timestamp-from-table-to-db/3654 "2011-11-23T23:14:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Mendonca](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@Joseph\_Mendonca](https://forum.inductiveautomation.com/u/Joseph_Mendonca)\
**Post date:** [November 23, 2011, 11:14pm UTC](https://forum.inductiveautomation.com/t/timestamp-from-table-to-db/3654/1 "2011-11-23T23:14:49Z")

</div>

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?

[code]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=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])`

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 28, 2011, 2:24pm UTC](https://forum.inductiveautomation.com/t/timestamp-from-table-to-db/3654/2 "2011-11-28T14:24:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [November 28, 2011, 4:47pm UTC](https://forum.inductiveautomation.com/t/timestamp-from-table-to-db/3654/3 "2011-11-28T16:47:04Z")

</div>

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