

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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?
- How to find the number of days and number of weeks between two dates in R?
- PHP program to find the total number of date between any two given dates
- 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
- Find the number of logins between two dates in MySQL
- What is the way to find business days between two specified dates in MySQL?
- Find objects between two dates in MongoDB?
- How to get number of quarters between two dates in Java
- 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
Advertisements