calculateAge static method
Calculate age from birth date
Example:
final birthDate = DateTime(1990, 1, 1);
FSDates.calculateAge(birthDate); // 33 (as of 2023)
Implementation
static int calculateAge(DateTime birthDate) {
final now = DateTime.now();
int age = now.year - birthDate.year;
if (now.month < birthDate.month ||
(now.month == birthDate.month && now.day < birthDate.day)) {
age--;
}
return age;
}