Menu

gitpiper

months_diff python Code Snippet in 2022

datebeginner

Last Updated: 26 November 2022

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).
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

python snippet similar to months_diff For You in November 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️