如何区分DateTime in Days:Minutes:Hours Format

时间:2021-09-06 21:30:43

I have two Dates in SQL Server table, I want difference between them in Days: Minutes: Hours Format

我在SQL Server表中有两个日期,我希望它们在Days:Minutes:Hours Format中有区别

How to get This??

怎么弄这个?

2 个解决方案

#1


3  

maybe this helps, found it on some site.

也许这有帮助,在某些网站上找到它。

In essence, you calculate the difference in seconds. After that, you calculate days, hours and the remainder in minutes

实质上,您可以以秒为单位计算差异。之后,您可以计算天数,小时数和余数(以分钟为单位)

DECLARE @INT INT

SET @INT = DATEDIFF(SECOND,GETDATE(),GETDATE()+1)

select 
convert(varchar(10), (@INT/86400)) + ':' + 
convert(varchar(10), ((@INT%86400)/3600)) + ':'+
convert(varchar(10), (((@INT%86400)%3600)/60)) + ':'+
convert(varchar(10), (((@INT%86400)%3600)%60)) as 'DD:HH:MM:SS'

#2


0  

Have a look at the DATEDIFF function.

看看DATEDIFF功能。

#1


3  

maybe this helps, found it on some site.

也许这有帮助,在某些网站上找到它。

In essence, you calculate the difference in seconds. After that, you calculate days, hours and the remainder in minutes

实质上,您可以以秒为单位计算差异。之后,您可以计算天数,小时数和余数(以分钟为单位)

DECLARE @INT INT

SET @INT = DATEDIFF(SECOND,GETDATE(),GETDATE()+1)

select 
convert(varchar(10), (@INT/86400)) + ':' + 
convert(varchar(10), ((@INT%86400)/3600)) + ':'+
convert(varchar(10), (((@INT%86400)%3600)/60)) + ':'+
convert(varchar(10), (((@INT%86400)%3600)%60)) as 'DD:HH:MM:SS'

#2


0  

Have a look at the DATEDIFF function.

看看DATEDIFF功能。