monthDelta method Null safety

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

Determines the number of months between two DateTime objects.

For example:

DateTime date1 = DateTime(year: 2019, month: 6, day: 15);
DateTime date2 = DateTime(year: 2020, month: 1, day: 15);
int delta = 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;
}