using the following:-
TimeSpan diff = dt2.TimeOfDay - dt1.TimeOfDay;
d1, d2 are 2 variables of type DateTime and they have got values in them
Now I want to check if there’s a difference of 12 hours b/w them
if(diff>12)
{
//do stuff
}
now of course it wont wont coz 12 is an int..so how do I check if the time is more than 12 hrs or not ?? need help with this if statement only..thnx
The general solution is to construct a
TimeSpanobject that corresponds to the cut-off:If the cut-off corresponds to a multiple of a ‘nice’ unit of time like days, hours, minutes, seconds or milliseconds as in your example, you could use the
TotalXXXproperty ofTimeSpan, as others have posted: