sql T_sql 计算两个时间的时间差(精确到秒)

declare @starttime varchar(8000)

set @starttime=  Cast(datediff(second,'2010-06-25 11:59:30','2010-06-27 12:58:00') as int)

 

select '2010-06-25 11:59:30 2010-06-27 12:58:00 的时间间隔是:'

+

cast(

(@starttime-(@starttime%3600))/(3600*24)

 as varchar)+''+

cast(

(@starttime-(@starttime%3600))/(3600) -((@starttime-(@starttime%3600))/(3600*24)*24)

as varchar) +'小时'+

cast

(

(@starttime-(@starttime%60))/60 -((@starttime-(@starttime%3600))/60)

as varchar

)

+'分钟'+cast((@starttime%60) as varchar)+'' as 时间差

 

返回结果如下图:

 

你可能感兴趣的:(sql T_sql 计算两个时间的时间差(精确到秒))