How to count the Number of days between two dates?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
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 Jul 23, 2012, 1:03 AM EDT
DateTime dt1 = new DateTime(2012, 7, 1);
DateTime dt2 = DateTime.Today;
double days = (dt2 - dt1).TotalDays;
Console.WriteLine(days); // 22
Add 1 to 'days' if you want it to be inclusive of both end points.
If you're not interested in fractional days, you can use the Days rather than the TotalDays property.