- 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

# How do I calculate number of days between two dates using Python?

In this article we will discuss how to find the number of days between two dates using Python.

We use the datetime module() to calculate the number of days between two dates using python.

## datetime() module

Python has a built-in datetime module that assists us in resolving a number of date-related issues. We just input the two dates with the date type and subtract them to discover the difference between the two dates, which gives us the number of days between the two dates.

### Syntax

The syntax of the date() method in datetime module is as follows.

datetime.date(year, month, day)

**Parameters**

- year: Takes this parameter as the year.
- month: Takes this parameter as the month.
- day: Takes this parameter as the day.

**Returns**

This function returns date object with same year, month and day. All arguments are required. Arguments may be integers, in the following ranges:

- MINYEAR <= year <= MAXYEAR
- 1 <= month <= 12
- 1 <= day <= number of days in the given month and year

### Example

In the following example code, we define the two dates between which we want to find the difference in days. Then subtract these dates to get a timedelta object and examine the day's property of this object to get the required result.

from datetime import date d0 = date(2011, 1, 8) d1 = date(2015, 8, 16) delta = d1 - d0 print('The number of days between the given range of dates is :') print(delta.days)

### Output

The output of the above code is as follows.

The number of days between the given range of dates is : 1681

- Related Questions & Answers
- How do I get the number of days between two dates in JavaScript?
- How can I calculate full 24hour days between two specified dates in MySQL?
- Finding Number of Days Between Two Dates JavaScript
- Python program to find number of days between two given dates
- Find number of days between two given dates in C++
- How to get the number of days between two Dates in JavaScript?
- How to find the number of days and number of weeks between two dates in R?
- How to count days between two dates in Java
- How do I generate days from the range of dates in MySQL?
- Calculate minutes between two dates in C#
- MySQL query to calculate the days between two dates from different columns but similar rows
- How to calculate the difference between two dates in JavaScript?
- How to get number of quarters between two dates in Java
- Find the number of logins between two dates in MySQL
- How to get the number of seconds between two Dates in JavaScript?