1

I want to calculate no of days remaining for particular day from today onwards. How to calculate difference between 2 dates in C#??

MakB
  • 11
  • 5
  • http://stackoverflow.com/questions/1170257/calculate-days-remaining-to-a-birthday – JsonStatham Jun 28 '13 at 09:02
  • 1
    `DateDiff("d",Day(Date()),#28/10/2013#)` returns 41547 because today is the 28th day of the month so `Day(Date())` returns 28 and `CDate(28)` is `1900-01-27`. Therefore, `DateDiff()` is counting the number of days between `1900-01-27` and `2013-10-28`. If you get rid of the `Day()` part then things should work better. – Gord Thompson Jun 28 '13 at 09:49

2 Answers2

3

(Note: This answer was written when the question was worded very differently)

Assuming your dates are DateTime or DateTimeOffset:

TimeSpan delta = date1 - date2
Sebastian Negraszus
  • 11,915
  • 7
  • 43
  • 70
-1
TimeSpan GetDelta(DateTime d1, DateTime d2)
{
    return (d1 - d2).TotalDays;
}
Liel
  • 2,407
  • 4
  • 20
  • 39