Answer the question
In order to leave comments, you need to log in
How to fix ValueError: time data "('2021-11-20',)" does not match format '%y-%m-%d'?
Hello, I'm trying to convert a date from the database into a string in order to compare them ">="
It gives the following error
Code:
@tasks.loop(seconds=2.0)
async def ban_loop():
getdatanow = datetime.now().date()
for ban in sql.execute(F"SELECT days FROM bans"):
getdays = str(ban)
ban1 = datetime.strptime(getdays, "%y-%m-%d")
if getdatanow >= ban1:
sql.execute(f"UPDATE bans SET ex = 'True'")
for bans in sql.execute(f"SELECT FROM bans WHERE ex = 'True'"):
if getdatanow > bans[2]:
guild = client.get_guild(806633419865718784)
await guild.unban(getallbannedid[4])
print(getallbannedid[4])
sql.execute(f"DELETE FROM bans WHERE banned = {bans[0]}")
db.commit()
print('Пользователь разбанен по истечению длительности наказания')
Answer the question
In order to leave comments, you need to log in
You don't have to do that getdays = str(ban)
. A query to the database gives you a tuple of data, instead of getting an element of this tuple, for some reason you turn it into a string, and you get this ( string ) ('2021-11-20', )
.
You are trying to parse this string according to the format "year-month-day", while your string looks like "bracketquote-year-month-dayquotecommabracket" does not match so to speak.
Plus, the wrong types were used. cheatsheet , scroll down to "Format Code List"
ban1 = datetime.strptime(ban[0], "%Y-%m-%d")
Maybe it's worth extracting the value from the tuple before converting it to a string and then converting it to a date?
...
getdays = ban[0]
ban1 = datetime.strptime(getdays, "%Y-%m-%d")
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question