# How to find the difference or gap of days between two dates in python

In this tutorial, We will see How to find the difference or gap of days between two dates in python. So Guy’s, No need to fear about it that how we will solve this problem. Here, I am going to provide a simple solution to this problem in python by using datetime module. In order to solve this problem in python language, we have to know datetime module in python language.

You may also like to read:

What is datetime module in python?

Python provide inbuilt module datetime which allow us to solve various problem related to date and time.

## To find the difference or gap of days between two dates in Python

So, let’s start to understand this problem in easy ways. We will follow these steps in python language:

1. First of all, we will include the date in our python program from datetime module by using import function.

`from datetime import date`

2. We will take the starting date and the ending date of calendar between which you have to find the difference or gap of days.

```Start=date(2019,7,1)
End=date(2019,8,15)```

3. Now, we will find the difference or gap of days between two dates as we have learned to Subtract two number by using minus sign (-) and print gap of days on output page.

```Gap=(End-Start).days
print("Days gap:")
print(Gap)```

#### Python program to find difference or gap of days

Python program:

```from datetime import date
Start=date(2019,7,1)
End=date(2019,8,15)
Gap=(End-Start).days
print("Days gap:")
print(Gap)```

Output of code:

```Days gap:
45```

So Guy’s, I hope you really enjoy this tutorial and feel free to leave a comment if you have any doubt.

### 2 responses to “How to find the difference or gap of days between two dates in python”

1. Vishal says:

Hello,
What if I want to create a code where the user can put in 2 dates?
Everywhere I see, I see the dates are already a part of the code, is there a way to let a user “input” 2 dates?
Thanks!

• Sumit Gupta says:

Hi Vishal,

This is code what you want:

import datetime

try:
firstDate = input(“Please Enter First Date (Y-m-d) like (2021-2-21) = “)
secondDate = input(“Please Enter Second Date (Y-m-d) like (2021-2-21) = “)
firstDateObj = datetime.datetime.strptime(firstDate, “%Y-%m-%d”)
secondDateObj = datetime.datetime.strptime(secondDate, “%Y-%m-%d”)
totalDays = (firstDateObj – secondDateObj).days
print(totalDays, “Day(s)”)
except ValueError as e:
print(e)