Skip to content

Home

Date difference in months

Calculates the month difference between two dates.

from math import ceil
from datetime import date

def months_diff(start, end):
  return ceil((end - start).days / 30)

months_diff(date(2020, 10, 28), date(2020, 11, 25)) # 1

More like this

Start typing a keyphrase to see matching snippets.