I am trying to get the half of a TimeSpan. My timespan is 21:00:00 so that’s 21 hours, I want to get the half of 21 hours which is 10.5 hours or 10:30:00
Is there a way I can get that value? I tried dividing the timespan by 2 but it won’t let me since it’s variable type is TimeSpan, i guess?
Any help would be appreciated thanks!
Hi @mimuhrin ,
We can convert timespan to seconds and we can divide by 2 so that we can get half of the timespan and we can convert back seconds to timespan. Please try with below expressions. Thanks.
Totalseconds = TimeSpan.Parse(timespan).TotalSeconds
FinalTimespan = Timespan.FromSeconds(Totalseconds)
similar as Oneliner:
ts2 = TimeSpan.FromTicks(CLng(ts1.Ticks / 2))
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.