Add days_from_now

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-28 16:19:51 +02:00
parent 37ed12021b
commit 7b576c1aa5

20
snippets/days_from_now.md Normal file
View File

@ -0,0 +1,20 @@
---
title: days_from_now
tags: date,intermediate
---
Calculates the date of `n` days from today.
- Use `datetime.date.today()` to get the current day.
- Use `datetime.timedelta` to add `n` days from today's date.
```py
from datetime import timedelta, date
def days_from_now(n):
return date.today() + timedelta(n)
```
```py
days_from_now(5) # date(2020, 11, 02)
```