Comparing dates is quite easy in Python. Dates can be easily compared using comparison operators (like <, >, <=, >=, != etc.). Let’s see how to compare dates with the help of
datetime module using Python.
Code #1 : Basic
d1 is greater than d2 : False d1 is less than d2 : True d1 is not equal to d2 : True
Code #2 : Sorting dates
One of the best ways to sort a group of dates is to store them into a list and apply
sort() method. This will sort all the dates which are available in the list. One can store the date class objects into the list using
2011-04-07 2011-05-02 2015-06-29 2018-05-24
Code #3 : Comparing Dates
date class objects, just like comparing two numbers.
Enter first person's date(DD/MM/YYYY) : 12/05/2017 Enter second person's date(DD/MM/YYYY) : 10/11/2015 The second person is older
- Argparse VS Docopt VS Click - Comparing Python Command-Line Parsing Libraries
- Data Ingestion via Excel: Comparing runtimes
- Python | Sort list of dates given as strings
- Python program to find number of days between two given dates
- Python | Difference between two dates (in minutes) using datetime.timedelta() method
- Formatting Dates in Python
- Matplotlib.dates.DateFormatter class in Python
- Matplotlib.dates.ConciseDateFormatter class in Python
- Matplotlib.dates.datestr2num() in Python
- Matplotlib.dates.epoch2num() in Python
- Matplotlib.dates.drange() in Python
- Matplotlib.dates.AutoDateFormatter class in Python
- Find number of days between two given dates
- How to sort an array of dates in C/C++?
- C++ program for Sorting Dates using Selection Sort
- Sort an array of dates in PHP
- PHP | Number of week days between two dates
- NLP | Using dateutil to parse dates.
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.