range between dates...
i want to get days,months,years in between two dates(two textboxes(datepickers)) in mvc..can anyone help....
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 2, 2014, 6:28 AM
string result = String.Format("{0} years, {1} months, {2} days", years, months, days);
Response.Write(result);
The output is:
14 years, 1 months, 21 days
The method always returns the positive difference between two dates and so it doesn't matter in what order they are presented to it.
In your case the parameters will, of course, be:
DateTime dt1 = DateTimePicker1.Value.Date;
DateTime dt2 = DateTimePicker2.Value.Date;