Click here to Skip to main content
15,889,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear sir,

I have two column one is hour and another one is minute column in datagrid. i want to display total hours and minutes in same column.

for example 10.160(means 10 hour and 160 minutes).my question is how to convert 160 minute to hour and add those hour with 10 hours and rest minute should display as well in sql server 2008
Posted
Comments
thatraja 23-Nov-13 2:44am    
why repost? :(
Did you check my answer there?
Mike Meinz 23-Nov-13 9:19am    
These problems arise from not following best practices for data design. The value should be in one column of the DataGrid. In the SQL Server database, the value should be stored in one column as a Date or Time Data Type. When computing, the DateTime structure method AddMinutes should be used to compute the new value. String formatting should be used to format as hh:mm.

1 solution

Try:
SQL
SELECT CONVERT(VARCHAR, ((Hours*60) + Mins) / 60) + ':' + CONVERT(VARCHAR, Mins % 60) AS [Time] FROM MyTable
 
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