Timspan returns only the number of days (as the highest value). Maybe there's another way for returning the Year? Not to mention DateDiff function from Microsoft.VisualBasic namespace? Any function from the standard .Net base classes?
Thanks.
Printable View
Timspan returns only the number of days (as the highest value). Maybe there's another way for returning the Year? Not to mention DateDiff function from Microsoft.VisualBasic namespace? Any function from the standard .Net base classes?
Thanks.
Given the fact that different months and years contain different numbers of days, paired with the fact that a TimeSpan has no specific start or end point with reference to any specific date and time, it is not possible for a TimeSpan to report a number of months or years. If you want a person's age in years then do it like this:or something like:Code:DateTime dob; // Date of birth.
DateTime currentDate = DateTime.Today;
int years = currentDate.Year - dob.Year;
if (currentDate.Month < dob.Month)
--years;
Code:int year = DateTime.Today.Month < dob.Month ? dob.Year - DateTime.Today.Year - 1 : dob.Year - DateTime.Today.Year;
Ok thanks a million.