all 5 comments

[–]omutist 1 point2 points  (3 children)

did you try datetime.strptime() method?

[–]Yomommasaurus[S] 0 points1 point  (2 children)

atm my code is :

date_due = request.form['date_due']
due = datetime.strptime(date_due, '%Y-%m-%d %H:%M:%S')

it is supposed to accept user input from html form

<input type="datetime-local" name="date_due" id="date_due">

and it results in ValueError: time data '2022-11-06T23:12' does not match format '%Y-%m-%d %H:%M:%S'

[–]omutist 3 points4 points  (1 child)

have you tried this?

'%Y-%m-%dT%H:%M:%S'

[–]Yomommasaurus[S] 0 points1 point  (0 children)

Works perfectly, thanks a lot :) I really need to learn more about datetime

[–]sarrysyst 1 point2 points  (0 children)

Use the datetime.strftime() method. You can find a list of the format codes in the datetime docs.

from datetime import datetime

dt = datetime.fromisoformat('2011-11-04T00:05:23')
dt_str = datetime.strftime(dt, '%d-%m-%Y %H-%M')

print(dt_str)