Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Compare Date Strings in Python



Python date implementations support all the comparision operators. So, if you are using the datetime module to create and handle date objects, you can simply use the <, >, <=, >=, etc. operators on the dates. This makes it very easy to compare and check dates for validations, etc.

Example

from datetime import datetime
from datetime import timedelta
today = datetime.today()
yesterday = today - timedelta(days=1)
print(today < yesterday)
print(today > yesterday)
print(today == yesterday)

Output

This will give the output −

False
True
False
Updated on: 2020-06-13T06:01:28+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements