如何在 SQL Server 2008 中将整数(时间)转换为 HH:MM:SS::00? [英] How to convert an integer (time) to HH:MM:SS::00 in SQL Server 2008?

查看:44
本文介绍了如何在 SQL Server 2008 中将整数(时间)转换为 HH:MM:SS::00?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个带有 time 列的表(数据类型是 integer),现在我需要将整数值转换为时间格式 HH:MM:SS:00 在 SQL Server 2008 中.

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.

在上面的time格式中还需要说明一下,00是否代表毫秒?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆