'Timedata convertion unsuccessfull [closed]
I am trying to create a Python Bot that takes a qr code from my email and sends it to me via Telegram when i want to. I was able to convert the email data in a list, in this way i am also able to access the date written in the email.
for context the email looks like this:
Gentile STEFANO ZIZZI,
La tua prenotazione per l'evento ANALISI MATEMATICA 1 in data 01/03/2022 09:00 è stata confermata.
L'aula in cui potrai seguire l'evento è: Aula Von Neumann.
Stampa e porta con te il seguente codice a barre:
20220222090620-ffc5d11f-760c-4449-975f-*********
So i have this multidimentional list where the elements are: 0 - the qr code 1 - the place 2 - the subject 3 - the date
and looks like this:
[['20220222090620-ffc5d11f-760c-4449-975f-********'], ['Aula Von Neumann.'], ['ANALISI MATEMATICA 1 '], ['01/03/2022 09:00']]
Why by running this code, it does not convert the date to datetime succeffuly?
data =''.join(lista[0][3])
if data:
date_time_obj = datetime.strptime(data,'%d/%m/%y %H:%M')
print ("The date is", date_time_obj)
Sorry if there's not the full code but it's honestly too long to copy here, and i think i've given most of the information anyways.
Error:
ValueError: time data '01/03/2022 09:00' does not match format
'%d/%m/%y %H:%M'
Solution 1:[1]
To match the date 2022 you must use the %Y, as %y refers to year displayed with 2 digits.
date_time_obj = datetime.strptime(data,'%d/%m/%Y %H:%M')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Albin Sidås |
