Get days as an int from a time interval?

I currently have this:

var x = Convert.ToString(dateTimePicker2.Value.Subtract(dateTimePicker1.Value)); int xDays = Convert.ToInt32(x.Substring(0,1)); 

But it is ugly and makes me unhappy inside (also does not work for two-digit intervals of the day, for example, 15). Is there a better way to do this?

+4
source share
1 answer

TimeSpan.Days returns an integer value representing the component of the days of the time value.

  var span = someDate.Subtract(anotherDate); int days = span.Days; 
+17
source

Source: https://habr.com/ru/post/1394322/


All Articles