select
days
,CAST(days * 24 * 60 * 60 as int) as totalseconds --days converted to full seconds
,CAST(days * 24 * 60 as int) as totalminutes --days converted to full minutes
,CAST(days * 24 as int) as totalfullhours --days converted to full hours
,CAST(days * 24 * 60 as int) % 60 as remainingminutes -- since the row above contains full hours, we need to find out how many minutes are in the split hours f ex 0.2 hours
,CAST(days * 24 * 60 * 60 as int) % 60 as remainingseconds -- this will always be 0 because of your precision
from YourTable
如果您仍然希望结果是单个字符串列(hh::mm),那么它将是
select
CAST(CAST(days * 24 as int) as varchar(10)) + ':' + RIGHT('0'+CAST(CAST(days * 24 * 60 as int) % 60 as varchar(10)),2)
from YourTable
1条答案
按热度按时间33qvvth11#
你似乎认为你需要使用nvarchar。但事实未必如此。如果你能把你的小时数存储为十进制。解决办法很简单
如果你想把它分解成小时分和秒,你需要把它转换成秒。一天有24小时,一小时有60分钟,一分钟有60秒。
一旦有了秒数,就可以使用除法运算符(/)和模运算符(%)。如果你把你的日子存储为十进制(3,1),你就不用担心秒了,因为分辨率太低了。
如果您仍然希望结果是单个字符串列(hh::mm),那么它将是