gpt4 book ai didi

sql - 如何获取两个日期时间之间的小时和分钟差异

转载 作者:行者123 更新时间:2023-12-02 13:50:14 25 4
gpt4 key购买 nike

如果我有两个这样的日期时间:

transtime_in, transtime_out

如何以以下格式获取这些日期时间之间的差异:

hh:mm
<小时/>

我用

DATEDIFF(hour, transtime_in, transtime_out) 

但我只得到时间。

最佳答案

试试这个 -

查询:

DECLARE 
@transtime_in DATETIME
, @transtime_out DATETIME

SELECT
@transtime_in = '2013-05-19 08:58:07.000'
, @transtime_out = '2013-05-19 16:40:53.000'

SELECT LEFT(CONVERT(VARCHAR(10), @transtime_out - @transtime_in, 108), 5)

输出:

-----
07:42

关于sql - 如何获取两个日期时间之间的小时和分钟差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16645641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com