ageYears property
int
get
ageYears
Returns the current age in full years.
Example:
DateTime(1990, 5, 12).ageYears; // 33
Implementation
int get ageYears {
if (this == null) return 0;
final now = DateTime.now();
int years = now.year - this!.year;
// if birthday hasn't happened yet this year, subtract one
if (now.month < this!.month ||
(now.month == this!.month && now.day < this!.day)) {
years--;
}
return years;
}