Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:43:50 +03:00
parent ab1ea476c5
commit a5ca5190e5
169 changed files with 0 additions and 626 deletions

View File

@ -0,0 +1,26 @@
---
title: Add days to date
type: snippet
tags: [date]
cover: orange-flower
dateModified: 2020-10-28T16:19:04+02:00
---
Calculates the date of `n` days from the given date.
- Use `datetime.timedelta` and the `+` operator to calculate the new `datetime.datetime` value after adding `n` days to `d`.
- Omit the second argument, `d`, to use a default value of `datetime.today()`.
```py
from datetime import datetime, timedelta
def add_days(n, d = datetime.today()):
return d + timedelta(n)
```
```py
from datetime import date
add_days(5, date(2020, 10, 25)) # date(2020, 10, 30)
add_days(-5, date(2020, 10, 25)) # date(2020, 10, 20)
```