Add days_diff

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-28 16:19:39 +02:00
parent 59c028870b
commit 37ed12021b

19
snippets/days_diff.md Normal file
View File

@ -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
```