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,25 @@
---
title: Date difference in months
type: snippet
tags: [date]
cover: succulent-11
dateModified: 2020-10-28T16:20:39+02:00
---
Calculates the month difference between two dates.
- Subtract `start` from `end` and use `datetime.timedelta.days` to get the day difference.
- Divide by `30` and use `math.ceil()` to get the difference in months (rounded up).
```py
from math import ceil
def months_diff(start, end):
return ceil((end - start).days / 30)
```
```py
from datetime import date
months_diff(date(2020, 10, 28), date(2020, 11, 25)) # 1
```