/// <summary> > /// Calculates the Nearest Age > /// </summary> > /// <param name="birthDate">Date of Birth</param> > /// <param name="currentDate">Current Date</param> > /// <returns></returns> > public Int GetAgeNearest(DateTime? birthDate, DateTime? currentDate) > { > int age = 0; > if (birthDate != null && currentDate != null) > { > age = (int) ((currentDate - birthDate).TotalDays/365.25); > } > return age; > }>
'System.Nullable<System.TimeSpan>' does not contain a definition for 'TotalDays' and no extension method 'TotalDays' accepting a first argument of type 'System.Nullable<System.TimeSpan>' could be found (are you missing a using directive or an assembly reference?)
>age = (int) (((DateTime)currentDate - (DateTime)birthDate).TotalDays/365.25);or
int age = (int)((currentDate.Value - birthDate.Value).TotalDays / 365.25);