How to deal with Rounding-off TimeSpan?

Posted by infant programmer on Stack Overflow See other posts from Stack Overflow or by infant programmer
Published on 2010-04-26T14:26:42Z Indexed on 2010/04/26 14:33 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

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,

© Stack Overflow or respective owner

Related posts about timespan

Related posts about c#