1

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 need YYYY-MM-DD-HH-SS

I've try:

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

But I got error.

What is the good syntax?

6
  • In sqlite datetime('now') will give the date in "YYYY-MM-DD HH:MM:SS" format. Here is sqlite date time doc. 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. 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. Feb 19 '20 at 20:29
0

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

SELECT CURRENT_TIMESTAMP()

So I ask the time via python:

from datetime import datetime

date = datetime.now()

Have a nice day

0

Datetime module of python does its job correctly but the real issue is of database....Its either problem of squlite3 or cs50's php.....but the value stored in table is "just the date" even if value provided is "both datetime".....I even tried by changing type of "datetime" field to "text" but the problem isn't solved.

You must log in to answer this question.

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