monthDelta static method

int monthDelta(
  1. DateTime startDate,
  2. DateTime endDate
)

Determines the number of months between two DateTime objects.

For example:

DateTime date1 = DateTime(2019, 6, 15);
DateTime date2 = DateTime(2020, 1, 15);
int delta = DateUtils.monthDelta(date1, date2);

The value for delta would be 7.

Implementation

static int monthDelta(DateTime startDate, DateTime endDate) {
  return (endDate.year - startDate.year) * 12 + endDate.month - startDate.month;
}