Skip to content

Commit

Permalink
Add days_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinityyi committed Oct 28, 2020
1 parent 59c0288 commit 37ed120
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions snippets/days_diff.md
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit 37ed120

Please sign in to comment.