Is it possible to compare a timespan to an integer in C#?
if say I want to know if a timespan is equal to 30 days, and if it is then do something?
Is it possible to compare a timespan to an integer in C#?
if say I want to know if a timespan is equal to 30 days, and if it is then do something?
There is the property TotalDays
There's also TotalHours
, TotalMinutes
, TotalSeconds
and TotalMilliseconds
. You should check out the TimeSpan-properties for more information
You can use the property Days
of the TimeSpan
object, which returns the days component of the time interval
if (ts.Days == 30)
{
// do something
}
TimeSpan t = new TimeSpan();
if(t.TotalDays==30)
{
//Do Something
}