1

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.stack.imgur.com/zLlV6.png

  • I'm confused. You want the date before 01/01/2010 and it's getting true when date is less than 01/0/2010 (which I assume you mean before). Please explain exactly what it is you're trying to do. Also, please include your code as text and not as an image. – ewokx Jun 02 '22 at 05:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 02 '22 at 06:32

1 Answers1

0

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'))
toptecshare
  • 166
  • 2
  • 24