Basit Khan

Basit Khan

  • NA
  • 336
  • 120.9k

Get Hour & Time in SQL

Nov 19 2015 1:22 AM
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.

Answers (1)