[英]Query to Convert Varchar HH:MM to Integer Minutes in SQL Server 2008
I am having a table in SQL Server where there is a column name TimeSpent Datatype Varchar(25)
. 我在SQL Server中有一个表,其中有一个列名
TimeSpent Datatype Varchar(25)
。 It basically stores Time as HH:MM
Format. 它基本上将时间存储为
HH:MM
格式。 As per the requirement now i want that it gives me actual timespent in Minutes ie 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). 根据现在的要求,我希望它给我以分钟为单位的实际时间,即01:00给我60、01:30->90。请帮助我在SQL Server 2008中编写查询,以便将Varchar(HH: MM)转换成Minutes(整数)。
SELECT top 1(substring(CONVERT(VARCHAR(5),TimeSpent,108),1,2)* 60 + substring(CONVERT(VARCHAR(5),TimeSpent,108),4,2)作为测试分钟
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.