# How to Get All Dates Between Two Dates in Python?

Published On: 06/10/2022 | Category: Python

Hi Guys,

Here, I will show you python get all dates between two dates. Here you will learn how to get all dates between two dates in python. you will learn python list all dates between two dates. you can see python get all dates between two datetime. You just need to some step to done how to get date range between two dates in python.

I'll provide two examples in this instance. The first example uses datetime and timedelta to obtain all dates between two dates, whereas the second uses pandas to do the same. Let's look at both scenarios and put them to work for you.

You can use these examples with python3 (Python 3) version.

So let's see bellow example:

### Example 1:

main.py
```from datetime import datetime, timedelta

# Create Custom Function
def date_range(start, end):
delta = end - start
days = [start + timedelta(days=i) for i in range(delta.days + 1)]
return days

startDate = datetime(2022, 10, 1)
endDate = datetime(2022, 10, 6)

datesRange = date_range(startDate, endDate);
print(datesRange)
```
Output:
```[
datetime.datetime(2022, 10, 1, 0, 0),
datetime.datetime(2022, 10, 2, 0, 0),
datetime.datetime(2022, 10, 3, 0, 0),
datetime.datetime(2022, 10, 4, 0, 0),
datetime.datetime(2022, 10, 5, 0, 0),
datetime.datetime(2022, 10, 6, 0, 0)
]
```

### Example 2:

main.py
```import pandas
from datetime import datetime, timedelta

startDate = datetime(2022, 6, 1)
endDate = datetime(2022, 6, 10)

# Getting List of Days using pandas
datesRange = pandas.date_range(startDate,endDate-timedelta(days=1),freq='d')
print(datesRange);
```
Output:
```DatetimeIndex(['2022-06-01', '2022-06-02', '2022-06-03', '2022-06-04',
'2022-06-05', '2022-06-06', '2022-06-07', '2022-06-08',
'2022-06-09'],
dtype='datetime64[ns]', freq='D')
```