TimeSpan Earlybeforetime = new TimeSpan();
Earlybeforetime = earlybefore.Subtract(Convert.ToDateTime(outtime);
Sometimes it returns a negative value. How do I convert the value to be always positive?
Negative values are returned when yours Earlybeforetime is earlier that outtime. if you want to have absolute "distance" between two points in time, you can use TimeSpan.Duration method, e.g:
TimeSpan first = TimeSpan.FromDays(5);
TimeSpan second = TimeSpan.FromDays(15);
TimeSpan final = first.Subtract(second).Duration();
Console.WriteLine(final);
this method will return absolute TimeSpan 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