603 B
603 B
title, tags, author, cover, firstSeen, lastUpdated
| title | tags | author | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|
| Date difference in months | date | maciv | blog_images/succulent-11.jpg | 2020-10-28T16:20:39+02:00 | 2020-10-28T16:20:39+02:00 |
Calculates the month difference between two dates.
- Subtract
startfromendand usedatetime.timedelta.daysto get the day difference. - Divide by
30and usemath.ceil()to get the difference in months (rounded up).
from math import ceil
def months_diff(start, end):
return ceil((end - start).days / 30)
from datetime import date
months_diff(date(2020, 10, 28), date(2020, 11, 25)) # 1