Q:

inserting datetime into database

Can anyone explain how to insert datetime into SQLite database using python?
which datatype should be datetime, I tried many different ways 
my doubt is based on the problem set 7 in cs50, we use flask as a web framework
history is the name of the database
transaction is name of field 
db.execute("INSERT INTO history (transaction) VALUES(:d)",
             d=datetime.datetime.today())

error message, I receive this message when I run the application 
builtins.RuntimeError
RuntimeError: near "transaction": syntax error [SQL: "INSERT INTO history (transaction) VALUES('2019-05-19 17:14:25')"] (Background on this error at: http://sqlalche.me/e/e3q8)

A:

transaction is a reserved word in SQLite.
sqlite> INSERT INTO history (transaction) VALUES('2019-05-19 17:14:25');
Error: near "transaction": syntax error

In order to disambiguate reserved words they have to be specially quoted. In this case as an identifier with double quotes.
sqlite> INSERT INTO history ("transaction") VALUES('2019-05-19 17:14:25');

Rather than constantly having to remember to quote transaction, I'd recommend renaming the column; created_at is very common for a row timestamp. I'd also recommend using an ORM rather than writing SQL by hand; it will handle all the quoting for you, and has a great many other benefits.

