diff --git a/snippets/days_diff.md b/snippets/days_diff.md new file mode 100644 index 000000000..d2ce985f0 --- /dev/null +++ b/snippets/days_diff.md @@ -0,0 +1,19 @@ +--- +title: days_diff +tags: date,beginner +--- + +Calculates the day difference between two dates. + +- Subtract `start` from `end` and use `datetime.timedelta.days` to get the day difference. + +```py +def days_diff(start, end): + return (end - start).days +``` + +```py +from datetime import date + +days_diff(date(2020, 10, 25), date(2020, 10, 28)) # 3 +```