getYearsAndMonthsFromDateTime static method

dynamic getYearsAndMonthsFromDateTime(
  1. DateTime dateTime, [
  2. bool getMonths = false
])

Implementation

static getYearsAndMonthsFromDateTime(
  DateTime dateTime, [
  bool getMonths = false,
]) {
  int days = DateTime.now().difference(dateTime).inDays;
  int years = days ~/ 365;
  int months = (days - (years * 365)) ~/ 30;

  return getMonths ? months : years;
}