I wish to add the date of the transaction in a DB (SQLite)

date = db.execute("""SELECT date('now')""")[0]["date('now')"]

But the date is only in format: 2020-02-18


I've try:

SELECT date('%Y-%m-%d %H-%M-%S','now');

But I got error.

What is the good syntax?

  • In sqlite datetime('now') will give the date in "YYYY-MM-DD HH:MM:SS" format. Here is sqlite date time doc. – DinoCoderSaurus Feb 18 '20 at 20:45
  • Even datetime('now') fail. I think the finance.db in CS50 don't support it. – saquiel Feb 19 '20 at 13:07
  • It absolutely does work in cs50 finance.db. Since you've solved it another way, the question is moot. – DinoCoderSaurus Feb 19 '20 at 14:52
  • I wish to understand why it's not working in my CS50 IDE. When I go to phpLiteAdmin => SQL => enter datetime('now'), I got: ERROR: near "datetime": syntax error. I wish to know something more, when asking time with python (or SQL), the return time is the BIOS time of the host computer or the internet time ? – saquiel Feb 19 '20 at 20:05
  • 1
    SELECT datetime('now') works in sqlite3 and phpLiteAdmin. sqlite returns UTC. Don't know about python, you'd have to research that. – DinoCoderSaurus Feb 19 '20 at 20:29

Well I can't ask for a SQL time maybe because SQLite is not a DB server. Even this code doesn't work:


So I ask the time via python:

from datetime import datetime

date = datetime.now()

Have a nice day

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .