I see that this question has been answered for Java, Javascript, and PHP, but not C#. So, how might one calculate the number of days between two dates in C#?
+2
A:
Use TimeSpan object which is the result of date substraction:
DateTime d1;
DateTime d2;
return (d1 - d2).TotalDays;
Vitaliy Liptchinsky
2009-10-22 13:49:00
+1
A:
I think this will do what you want:
DateTime d1 = DateTime.Now;
DateTime d2 = DateTime.Now.AddDays(-1);
TimeSpan t = d1 - d2;
double NrOfDays = t.TotalDays;
Cloud
2009-10-22 13:49:47
+1
A:
DateTime xmas = new DateTime(2009, 12, 25);
double daysUntilChristmas = xmas.Subtract(DateTime.Today).TotalDays;
Philip Wallace
2009-10-22 13:49:56