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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 2, 2014, 2:28 AM EDT
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;