subtractYears method

DateTime subtractYears(
  1. int years
)

Subtracts the specified number of years from the current DateTime.

NOTE: you WILL lose Feb 29th when adding and subtracting 1 year

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

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

Implementation

DateTime subtractYears(int years) {
  if (years == 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(years: years).dateTime;
}