
- 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
Python program to find number of days between two given dates
To find the number of days between tow dates, we are using the Python datetime module. At first, import the required library −
from datetime import date
Create date objects and input the dates from which you want to calculate the days −
date1 = date(2021, 7, 20) date2 = date(2021, 8, 30)
Get the difference between the above 2 dates in the form of days −
(date2 - date1).days
Example
Following is the code −
from datetime import date # both the dates date1 = date(2021, 7, 20) date2 = date(2021, 8, 30) print"Date 1 = ", date1; print"Date 2 = ", date2; resDays = (date2 - date1).days print"Days between two dates = ", resDays
Output
This will produce the following output −
Date 1 = 2021-07-20 Date 2 = 2021-08-30 Days between two dates = 41
- Related Articles
- Find number of days between two given dates in C++
- Finding Number of Days Between Two Dates JavaScript
- How do I calculate number of days between two dates using Python?
- PHP program to find the total number of date between any two given dates
- How to find the number of days and number of weeks between two dates in R?
- How to get the number of days between two Dates in JavaScript?
- PHP program to find number of days in every week between two given date ranges
- How do I get the number of days between two dates in JavaScript?
- How to count days between two dates in Java
- What is the way to find business days between two specified dates in MySQL?
- Find the number of logins between two dates in MySQL
- How to calculate the weeks and days between two dates in Excel?
- Program to find minimum number of days to make m bouquets using Python
- Program to find minimum number of days to eat N oranges in Python
- How to get number of quarters between two dates in Java

Advertisements