0

Issue inserting Date(Date formate) into mariadb using Python

I have made this code to write a kind of Log into a database table: _________________________________________________ SQL table head: MariaDB [genre]> show columns from history; +--------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+---------+------+-----+---------+----------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | Genre_ID_1 | int(11) | NO | | NULL | | | Genre_ID_2 | int(11) | NO | | NULL | | | Edition_Date | date | YES | | NULL | | +--------------+---------+------+-----+---------+----------------+ 4 rows in set (0.027 sec) __________________________________________________ python code: cursor.execute("INSERT INTO genre.history(Genre_ID_1, Genre_ID_2, Edition_Date) VALUES (?, ?, ?))", (int(input("ID 1:")), int(input("ID 2:"))), date.today()) __________________________________________________ I have tried differrent ways, using '?' and '%b' instead of '%s' and also inderting the Date as date formate or as string but whatever I do I'm getting this Error: Traceback (most recent call last): File "D:\Random Prog\test.py", line 29, in <module> cursor.execute("INSERT INTO genre.history(Genre_ID_1, Genre_ID_2, Edition_Date) VALUES (?, ?, %s))", TypeError: an integer is required (got type str) when using '%s' and 'date.today()' or another like that TypeError: an integer is required (got type str) when using '%b' and 'date.today() Can you please help me?

12th May 2021, 9:15 AM
Niclas Fuchs
Niclas Fuchs - avatar
2 Réponses
0
from datetime import dáte today=dáte.today() d1=today.strftime("%Y-%m-%d)
12th May 2021, 7:04 PM
Václav Dostál
Václav Dostál - avatar
0
And then d1 in i INSERT INTO ... VALUES (?,?,d1) Beacause mariadb needs date in format Y-m-d aka 2021-05-12
12th May 2021, 7:07 PM
Václav Dostál
Václav Dostál - avatar