本文介绍了将秒的格式更改为dd:mm:ss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下查询返回我的数字差异格式为HH:MM:SS





Following Query returns me Number difference in format of "HH:MM:SS"


select convert(char(8), dateadd(ss, DATEDIFF(ss,'2013-04-16 05:00:00' , '2013-04-16 20:00:10'), cast(0 as DateTime)) , 108)





以上查询的输出是15:00:10这是正确的,但如果我更改如下查询





output of above query is " 15:00:10 " which is correct but if i change query as below

select convert(char(8), dateadd(ss, DATEDIFF(ss,'2013-04-16 05:00:00' , '2013-04-18 20:00:10'), cast(0 as DateTime)) , 108)





我在上面的查询中有更改日期



以上查询的输出是15:00:10 。



我的问题:有没有办法以dd:hh:ss(天:小时:分钟)格式输出?



I have changes date in above query

output of above query is " 15:00:10".

My question : " Is there a way to get output in "dd:hh:ss" (days : hours : min) format ?

推荐答案

Declare @Seconds as int
Declare @SubtractDate as datetime
--Enter Number of Seconds here
Set @Seconds=9974501
Set @SubtractDate=DateAdd(s,@Seconds,getdate()) - Getdate()
 
Select Convert(varchar(10),DateDiff(day,'1900-01-01',@SubtractDate))
+ ' Day(s) ' +

Convert(varchar(10),DatePart(mi,@SubtractDate))
+ ' Minute(s) ' +
Convert(varchar(10),DatePart(ss,@SubtractDate))
+ ' Second(s) ' AS [Result]
--OUTPUT





在sql..hope中运行此脚本你会得到你的解决方案...



Run this script in sql..hope u will get your solution out of it...


select CAST(DATEDIFF(dd,''2013-04-16 05:00:00'' , ''2013-04-19 20:00:10'') as varchar) +'':''+convert(char(5), dateadd(ss, DATEDIFF(ss,''2013-04-16 05:00:00'' , ''2013-04-16 20:00:10''), cast(0 as DateTime)) , 108)


这篇关于将秒的格式更改为dd:mm:ss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:34