How to deal with Rounding-off TimeSpan?
- by infant programmer
I take the difference between two DateTime fields, and store it in a TimeSpan variable, Now I have to round-off the TimeSpan by the following rules:
if the minutes in TimeSpan is less than 30 then Minutes and Seconds must be set to zero,
if the minutes in TimeSpan is equal to or greater than 30 then hours must be incremented by 1 and Minutes and Seconds must be set to zero.
TimeSpan can also be a negative value, so in that case I need to preserve the sign..
I could be able to achieve the requirement if the TimeSpan wasn't a negative value, though I have written a code I am not happy with its inefficiency as it is more bulky ..
Please suggest me a simpler and efficient method.
Thanks regards,