Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
Hi guys,

I have to calculate total time into hours & minutes,

how to calculate if i have time in decimals.
15.35 + 15.35

how to get this result: 31.10 hrs

how can i divide this into hh:mm

can anyone please help me to write the formula for this.

Thanks
Posted
Updated 2-Dec-14 6:14am
v2
Comments
[no name] 2-Dec-14 12:02pm    
Rhetorical question ...

How many minutes in an hour?
abdul subhan mohammed 2-Dec-14 12:15pm    
i have updated my question plz check
Ravi Bhavnani 2-Dec-14 12:17pm    
Wrong again. 15.35 hrs + 15.35 hrs = 30.70 hrs, or 30 hrs and 42 minutes, not 31 hrs and 10 minutes.

/ravi
abdul subhan mohammed 2-Dec-14 12:44pm    
its 15hr:35mins + 15hr:35mins, so why not, 31hrs:10mins
Ravi Bhavnani 2-Dec-14 13:12pm    
Because there are 60 (not 100) minutes in an hour. So 15.15 hours is 15hr:09mins not 15hr:15 mins.

/ravi

1 solution

I think what you simply want to do is:
TimeSpan ts1 = TimeSpan.FromHours (12.34);
TimeSpan ts2 = TimeSpan.FromHours (56.78);
TimeSpan sum = ts1 + ts2;
Console.WriteLine ("Total timespan = {0}hrs which is {1}hrs and {2}mins",
                   sum.TotalHours, sum.Hours, sum.Minutes);
/ravi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900