To calculate Day, month, year between two date or simply we can say that age calculation, use the below code:-
DateTime Birth = new DateTime(1947, 8, 15);
DateTime Today = DateTime.Now;
TimeSpan Span = Today - Birth;
DateTime Age = DateTime.MinValue + Span;
// Note:
MinValue is 1/1/1 so we have to Subtract.
int Years = Age.Year - 1;
int Months = Age.Month - 1;
int Days = Age.Day - 1;
string str = string.Format("Age = {0} Year, {1} Months, {2} Days.", Years, Months, Days);
No comments:
Post a Comment