Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
strptime convert string to date
from datetime import datetime
chday = datetime.strptime('datetime.date(2018, 12, 31)', 'datetime.date(%Y, %m, %d)')
today = datetime.today()
print(today < chday)
print(today > chday)
print(today == chday)
type(chday)
True
False
False
<class 'datetime.datetime'>
The simplest option (and the most insecure):
>>> import datetime
>>> in_str = "datetime.date(2018, 12, 11)"
>>> type(in_str)
<class 'str'>
>>> res = eval(in_str)
>>> res
datetime.date(2018, 12, 11)
>>> type(res)
<class 'datetime.date'>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question