
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to 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
- Related Articles
- Compare date strings in MySQL
- How to compare two strings using regex in Python?
- How to compare strings in Java?
- How to compare two strings in Golang?
- How to compare two strings in Perl?
- How to initialize and compare strings?
- How to Initialize and Compare Strings in Java?
- How to Initialize and Compare Strings in C#?
- How to parse Date strings in Golang?
- Python Program to compare two strings by ignoring case
- How do I compare strings in Java?
- Compare Strings in Arduino
- How to compare two JavaScript Date Objects?
- Java Program to Compare Strings
- How to compare two strings without case sensitive in Java

Advertisements