subtractYears method

  1. @useResult
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

@useResult
DateTime subtractYears(int years) {
  if (years == 0) {
    return this;
  }

  return Jiffy.parseFromDateTime(this).subtract(years: years).dateTime;
}