Created
February 8, 2020 12:45
-
-
Save BastinRobin/de38aff4b62c6cbf7bcfbdf2f9c601dd to your computer and use it in GitHub Desktop.
Dates Between Two Days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime, timedelta | |
| d1 = datetime.strptime('2020-12-01', '%Y-%m-%d') | |
| d2 = datetime.strptime('2021-12-01', '%Y-%m-%d') | |
| def date_between(start, end): | |
| """ | |
| Returns list of all dates between given `start and end` | |
| :param start: Start date | |
| :type start: { type_description } | |
| :param end: End Date | |
| :type end: { type_description } | |
| :returns: { list of all dates range } | |
| :rtype: { return_type_description } | |
| """ | |
| d1 = datetime.strptime(start, '%Y-%m-%d') | |
| d2 = datetime.strptime(end, '%Y-%m-%d') | |
| diff = d2 - d1 | |
| return [(d1 + timedelta(i)).strftime('%Y-%m-%d') for i in range(diff.days + 1)] | |
| print(date_between('1980-01-10', '2000-02-10')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment