Reputation: 11
i am not able to fetch accurate date based on condition it is giving me wring output. i want to fetch the date which is before 01/01/2010 but it is giving true even date is less than 01/01.2010
https://i.sstatic.net/zLlV6.png
Upvotes: 1
Views: 42
Reputation: 166
You should convert string to datetime to compare.
from datetime import datetime
#date_time_str = '1-1-2010'
def str_to_date(date_time_str):
return datetime.strptime(date_time_str, '%d-%m-%Y') # y - two digit(19), Y - four digit(2019)
def compare_date_from_str(str1, str2):
return str_to_date(str1) > str_to_date(str2)
print(compare_date_from_str('1-1-2010', '11-12-2009'))
Upvotes: 0