Reputation: 11403
Q:
If i have two periods in the following format .ToString("H:m");
and i wanna to firstly subtract the end period from the first period ,then round the result .like the following example:
13:00 ---->First period.
13.45 ---->Last period.
the result 45
----> round to 60
if the result = 75
for example then round to 120
Upvotes: 2
Views: 153
Reputation: 9680
Something like this
var t1 = TimeSpan.Parse("13:00").TotalMinutes;
var t2 = TimeSpan.Parse("13:45").TotalMinutes;
var round = (1 + ((int)(t2 - t1) / 60)) * 60; //Assuming t2 is always greater than t1
Hope this is what your looking for.
Upvotes: 3
Reputation: 244
You can use datetime.parse to get two datetime objects for first and last period then subtract them using lastperiod.subtract(firstperiod) this will return u a timespan object you can then round it as you want
Upvotes: 0