I considered maybe I was stuck in some sort of space time anomaly and it really was just constantly January 1, 1970, but then I realized I’m still using the internet, so no joy.
Maybe you need to use the TIMESTAMP keyword in your query?
Also just a suggestion but you appear to be doing doing unnecessary tag reads in the script. You could do it like this instead.
stop_time = system.tag.getTagValue("[System]Gateway/CurrentDateTime")
# The script was reading the same value for this so why read again?
start_time = stop_time
# Doing the write after the read
system.tag.write("gateway/last_cycle_start", start_time)
system.tag.write("gateway/last_cycle_stop", stop_time)
uname = system.tag.getTagValue("gateway/last_user_start")
system.db.runPrepUpdate("INSERT INTO rundata (run, start, stop, username) " + "VALUES (?,?,?,?)", ["0",start_time, stop_time, uname])