1
我在使用pyscopg2插入语句将日期时间戳插入sql数据库时遇到了问题。使用pyscopg2和PostgreSQL将datetime插入到数据库中
以下代码所做的每次按下按钮时,都应该在包含buildingID(仅为文本)和按钮按下时的日期和时间的数据库中插入一行。
我只是不知道如何插入当前日期和时间。
# Inserts data into local database
def insertLocalDB():
# Open a cursor to perform database operations
cur = conn.cursor()
cur.execute("INSERT INTO test_table (buildingID,datetime) VALUES(%s,%s)",
("01", datetime)) #HAS TO BE CURRENT DATE AND TIME
# Make the changes to the database persistant
conn.commit()
# Close communication with the database
cur.close()