将数字转换为时间跨度 [英] convert numeric into time span

查看:104
本文介绍了将数字转换为时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数值转换为时间(HH:MM).

How can i convert numeric value in to time (HH:MM).

推荐答案

您可以像下面的
那样编写sql脚本
You can write sql script like below
declare @time int
set @time = 635

select cast((@time / 60) as varchar(2)) + ' hr : ' + cast((@time % 60) as varchar(2))+' min'


SQL没有用于时间跨度的数据类型-因此,除了VARCHAR之外,没有任何其他可以作为单个项目返回的数据.
SQL doesn''t have a data type for timespans - so there is nothing you can return as a single item other than VARCHAR.
DECLARE @TIME INT
SET @TIME = 635
SELECT CONVERT(VARCHAR(10), @TIME / 100) + ' hours, ' + CONVERT(VARCHAR(10), @TIME % 100) + ' minutes'



或者您可以将其作为两列返回.



Or you could return it as two columns.

DECLARE @TIME INT
SET @TIME = 635
SELECT @TIME / 100 AS [Hours], @TIME % 100 AS [Minutes]


减去当前时间的结果值"
检查此代码

"substract the resultant value from current time"
check this code

DECLARE @TIME numeric
SET @TIME = 635
select CONVERT(VARCHAR(5),dateadd(MI, -((CAST( @TIME/100 as int)*60)+ RIGHT(@TIME,2)), getdate()),24)


这篇关于将数字转换为时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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