两个日期之间的 SQL 时差导致 hh:mm:ss [英] SQL time difference between two dates result in hh:mm:ss

查看:20
本文介绍了两个日期之间的 SQL 时差导致 hh:mm:ss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算两个日期之间的时差时遇到了一些困难.

I am facing some difficulty with calculating the time difference between two dates.

我想要的是,我有两个约会对象

What I want is, I have two dates let say

@StartDate = '10/01/2012 08:40:18.000'
@EndDate='10/04/2012 09:52:48.000'

所以 hh:mm:ss 形式的两个日期之间的差异是 72:42:30.

so the difference between two dates in the form of hh:mm:ss is 72:42:30.

如何在 T-SQL 查询中获得此结果?

How can I get this result in a T-SQL query?

推荐答案

declare @StartDate datetime, @EndDate datetime

select @StartDate = '10/01/2012 08:40:18.000',@EndDate='10/04/2012 09:52:48.000'

select convert(varchar(5),DateDiff(s, @startDate, @EndDate)/3600)+':'+convert(varchar(5),DateDiff(s, @startDate, @EndDate)%3600/60)+':'+convert(varchar(5),(DateDiff(s, @startDate, @EndDate)%60)) as [hh:mm:ss]

此查询对您有帮助.

这篇关于两个日期之间的 SQL 时差导致 hh:mm:ss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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