如何在SQL Server 2008中将整数(时间)转换为HH:MM:SS :: 00? [英] How to convert an integer (time) to HH:MM:SS::00 in SQL Server 2008?
本文介绍了如何在SQL Server 2008中将整数(时间)转换为HH:MM:SS :: 00?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我有一个表格,一个时间
列(数据类型是整数
),现在我需要转换SQL Server 2008中的整数值到时间格式 HH:MM:SS:00
Here I have a table with a time
column (datatype is integer
), now I need to convert the integer value to time format HH:MM:SS:00
in SQL Server 2008.
还需要澄清以上时间
格式,是否表示毫秒?
Also need clarification in the above time
format, whether 00 represents milliseconds?
请帮忙。
示例:23421155代表23:42:11:55; 421151代表00:42:11:51
example: 23421155 represents 23:42:11:55; 421151 represents 00:42:11:51
希望现在很清楚。
推荐答案
declare @T int
set @T = 10455836
--set @T = 421151
select (@T / 1000000) % 100 as hour,
(@T / 10000) % 100 as minute,
(@T / 100) % 100 as second,
(@T % 100) * 10 as millisecond
select dateadd(hour, (@T / 1000000) % 100,
dateadd(minute, (@T / 10000) % 100,
dateadd(second, (@T / 100) % 100,
dateadd(millisecond, (@T % 100) * 10, cast('00:00:00' as time(2))))))
结果:
hour minute second millisecond
----------- ----------- ----------- -----------
10 45 58 360
(1 row(s) affected)
----------------
10:45:58.36
(1 row(s) affected)
这篇关于如何在SQL Server 2008中将整数(时间)转换为HH:MM:SS :: 00?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文