Reputation: 7664
I need to do a calculation for my crystal report.
In report, there will be Times(in Hour:Min:Sec)like this..
00:12:34
00:52:12
23:19:56
and so on..
I need to add them together so that..results will be
Hr:min:ss
Hr may be more than 100..
but can't change to day
How to achieve that?
Thanks a lot..
Upvotes: 1
Views: 2497
Reputation: 65466
Look up the TimeSpan.Parse method like this.
var t1 = TimeSpan.Parse("00:12:34");
var t2 = TimeSpan.Parse("00:52:12");
var t3 = TimeSpan.Parse("23:19:56");
var result = t1 + t2 + t3
Console.WriteLine("Total time is {0} Hours {1} Mins {2} secs",
result.Days * 24 + result.Hours, result.Minutes, results.Seconds);
Upvotes: 2
Reputation: 40497
It you are getting hh:mm:ss only then this will be easy:
hh x 60 x 60 + mm x 60 + ss
and then get hours, mins and seconds from it.
If you are getting DateTime
object then you can get hours, mins and convert them to seconds and use same technique as above.
Upvotes: 0