subtractMonths method

DateTime subtractMonths(
  1. int months
)

Subtracts the specified number of months from the current DateTime.

Args: months (int): The number of months to subtract.

Returns: DateTime: A new DateTime object with the subtracted months.

Implementation

DateTime subtractMonths(int months) {
  if (months == 0) {
    // same
    return this;
  }

  // We used the Jiffy package to add years, months, etc
  // https://stackoverflow.com/questions/54792056/add-subtract-months-years-to-date-in-dart
  return Jiffy.parseFromDateTime(this).subtract(months: months).dateTime;
}