public static int CalculateAge(DateTime? StartDate, DateTime CurrentDate) >>>>>> { >>>>>> >>>>>> int YearsPassed = CurrentDate.Year - StartDate.Year; >>>>>> // Are we before the birth date this year? If so subtract one year from the mix >>>>>> if (CurrentDate.Month < StartDate.Month || (CurrentDate.Month == StartDate.Month && CurrentDate.Day < StartDate.Day)) >>>>>> { >>>>>> YearsPassed--; >>>>>> } >>>>>> return YearsPassed; >>>>>> }>>>>>>
int policyYear = CalculateAge(this.Entity.IssueDate, DateTime.Now);>>>>>>
'System.Nullable<System.DateTime>' does not contain a definition for 'Year' and no extension method 'Year' accepting a first argument of type 'System.Nullable<System.DateTime>' could be found
>>>>>>public static int CalcAge(DateTime StartDate, DateTime EndDate) >>> { >>>//.... >>> }so
if (IssueDate != null) >>> { >>> int age = CalcAge((DateTime)IssueDate, DateTime.Now); >>> }>>