i want to convert the timespan diff value always positive
My code is here :
TimeSpan lateaftertime = new TimeSpan(); lateaftertime = lateafter - Convert.ToDateTime(intime);
i want to get the result of lateaftertime always positive.. please help me..
A TimeSpan object represents a time interval (duration of time or elapsed time) that is measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The TimeSpan structure can also be used to represent the time of day, but only if the time is unrelated to a particular date.
/ˈtaɪm.spæn/ a period of time within which something happens, or between two events: The attacks all happened less than 5 miles apart within a three-week time span.
The default value is TimeSpan(30, 23, 59, 59) .
You can use lateaftertime.Duration()
to get a non-negative span.
You could use Math.Abs():
lateaftertime = new TimeSpan(Math.Abs(lateaftertime.Ticks));
User V4Vendetta made the right call in a comment though. Use the TimeSpan.Duration property, it always returns the absolute value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With