获取时间和时间SQL中的时间 [英] Get Hour & Time in SQL

查看:56
本文介绍了获取时间和时间SQL中的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的



在我的表格中,我有两列开始和结束两种数据类型都是日期时间。



我想得到时间和时间。



我用了一个小时



DATEDIFF (小时,Dr_TimeStart,Dr_TimeEnd)



我得到了一小时。但是当开始和结束列数据少于小时意味着时间,开始是0:00和结束0:15然后返回小时是0



这就是我使用的原因分钟



DATEDIFF(mi,Dr_TimeStart,Dr_TimeEnd)



然后我用了这个案子
当$ DATEDIFF(hh,dbo.Trn_Daily3.Dr_TimeStart,dbo.Trn_Daily3.Dr_TimeEnd)>


0然后DATEDIFF(hh,dbo.Trn_Daily3.Dr_TimeStart,dbo.Trn_Daily3.Dr_TimeEnd)否则DATEDIFF(mi,dbo.Trn_Daily3.Dr_TimeStart,dbo.Trn_Daily3.Dr_TimeEnd)/ 60结束



我想要的是



我想显示时间和时间



请帮忙在这个



谢谢

Basit。

Dear

In my table I have two Column Start & End both Data Type is datetime.

I want to get the hour and time.

I used this one for hour

DATEDIFF(hour,Dr_TimeStart,Dr_TimeEnd)

I got the hour. But when the Start and End column data are less then hour means time, Start is 0:00 and End 0:15 then return hour is 0

that's why i used min

DATEDIFF(mi,Dr_TimeStart,Dr_TimeEnd)

then i used the case

case when DATEDIFF(hh, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd) > 0 then DATEDIFF(hh, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd) else DATEDIFF(mi, dbo.Trn_Daily3.Dr_TimeStart, dbo.Trn_Daily3.Dr_TimeEnd) / 60 end

What i want is

I want to show the hour and time

Please help on this

Thanks
Basit.

推荐答案

试试如下,

Try like below,
DECLARE @StartDate DATETIME;
DECLARE @EndDate DATETIME;

SET @StartDate = '2015-11-18 00:00:16';

SET @EndDate = '2015-11-18 00:55:36';

select CONVERT(varchar(10), DATEDIFF(HOUR,@StartDate,@EndDate)) +':'+CONVERT(varchar(10), DATEDIFF(MINUTE,@StartDate,@EndDate)%60 )


这篇关于获取时间和时间SQL中的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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