Reputation: 2991
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).
Upvotes: 6
Views: 58155
Reputation: 11
SELECT top 1 (substring(CONVERT(VARCHAR(5), TimeSpent, 108), 1, 2) * 60 + substring(CONVERT(VARCHAR(5), TimeSpent, 108), 4, 2)) as minutes from test
Upvotes: 0