Query to Convert Varchar HH:MM to Integer Minutes in SQL Server 2008
sql, sql-server, sql-server-2008
Solution
Try
SELECT LTRIM(DATEDIFF(MINUTE, 0, TimeSpent))
FROM yourtable
Given
| TIMESPENT |
-------------
| 00:12 |
| 01:05 |
| 10:00 |
Output:
| MINUTES |
-----------
| 12 |
| 65 |
| 600 |
Here is SQLFiddle
Problem
I am having a table in SQL Server where there is a column name `TimeSpent Datatype Varchar(25)`. It basically stores Time as `HH:MM` Format. As per the requirement now i want that it gives me actual timespent in Minutes i.e. 01:00 gives me 60, 01:30 -> 90. Please help me to write the query in SQL Server 2008 , so that will convert Varchar (HH:MM) into Minutes(integer).