如何以时间格式检索新列中的两列差异?

如何以时间格式检索新列中的两列差异?

问题描述:

例如,我的输入时间:

记录时间卸载时间

11:37:05 PM 11:39:09 PM

11:44:56 PM 1:7:23 AM



我的输出应该是这样的:



记录时间卸载时间总时间

11:37:05 PM 11:39:09 PM 0:2:04

11:44:56 PM 1:7:23 AM 1:22:27



如何在sql中获取此内容?

For example, my input time:
record time unload time
11:37:05 PM 11:39:09 PM
11:44:56 PM 1:7:23 AM

My output should look like:

record time unload time total time
11:37:05 PM 11:39:09 PM 0:2:04
11:44:56 PM 1:7:23 AM 1:22:27

How can I get this in sql?

请参阅下文回答: -

see the below answer:-
SELECT datediff(Minute,'2006-11-10 05:47:53.497','2006-11-10 08:48:10.420')





还查看以下链接帮助你



http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74746 [ ^ ]

http://msdn.microsoft.com/en-us/library/ms189794.aspx [ ^ ]


select

    convert(varchar,datediff(hh,convert(datetime,[record time]) ,convert(datetime,[unload time]) ))
    + ':' +
    convert(varchar,datediff(mi,convert(datetime,[record time]) ,convert(datetime,[unload time]) )%60)
    + ':' +
    convert(varchar,datediff(ss,convert(datetime,[record time];) ,convert(datetime,[unload time]) )%60)
    as Duration
    
From YourTable



快乐编码!

:)


Happy Coding!
:)