Subtracting two dates

前端 未结 3 1105
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 03:05

I have two calendars and each return a DateTime from calendar.SelectedDate.

How do I go about subtracting the two selected dates from each other, giving me the amoun

3条回答
  •  醉话见心
    2020-12-29 03:38

    Think about it.
    How do you express a difference betwen two dates? With another date?
    That's why you need the TimeSpan

    DateTime dtToday = new System.DateTime(2012, 6, 2, 0, 0, 0);
    DateTime dtMonthBefore = new System.DateTime(2012, 5, 2, 0, 0, 0);
    TimeSpan diffResult = dtToday.Subtract(dtMonthBefore);
    Console.WriteLine(diffResult.TotalDays);
    

提交回复
热议问题