Created
June 19, 2021 01:28
-
-
Save luisgdev/7324e4fd3bb915b6a47b10034b588169 to your computer and use it in GitHub Desktop.
Returns how many days there are between 2 given dates.
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 date | |
| def format_date(plain_date): | |
| sep_date = plain_date.split('/') | |
| # Convert string numbers into int variables | |
| # sep_date = [int(item) for item in sep_date] | |
| sep_date = list(map(int, sep_date)) | |
| # plain date is DD/MM/YYYY, so ... | |
| day, month, year = sep_date | |
| return date(year, month, day) | |
| def count_days(data): | |
| for item in data: | |
| n_days = (format_date(item['arrival']) - format_date(item['order'])).days | |
| if n_days < 0: | |
| n_days += 365 | |
| print(f'The order arrived after {n_days} days.') | |
| if __name__ == '__main__': | |
| dates = [ | |
| {"order": "20/08/2019", "arrival": "30/08/2019"}, | |
| {"order": "30/12/2019", "arrival": "21/01/2020"}] | |
| count_days(dates) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment