2 Replies - 1301 Views - Last Post: 23 August 2012 - 05:52 AM

#1 mil1234  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 109
  • Joined: 01-February 09

date/time difference between 2 columns

Posted 23 August 2012 - 03:18 AM

Hi to all,

i have 3 columns 1) StartDate, 2) EndDate and 3) TotalHours . I want to put a function in computed column specification of TotalHours so that when the StarDate and EndDate are inserted the hours are subtracted and the total hours is automatically filled up. I was triying with this but the total hours property is still getting null:

(datediff(hour,[StartDate],[EndDate]))


Any ideas??

Thanks....

Is This A Good Question/Topic? 0
  • +

Replies To: date/time difference between 2 columns

#2 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: date/time difference between 2 columns

Posted 23 August 2012 - 05:29 AM

Hi,
This will help you
  DATEDIFF(hh, StartDate, EndDate) AS TotalHours   


Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,596
  • Joined: 16-October 07

Re: date/time difference between 2 columns

Posted 23 August 2012 - 05:52 AM

You're using the correct function.
e.g. This will get you 24:
select datediff(hour, GetDate()-1, GetDate())



However, this will get you null:
select datediff(hour, GetDate()-1, null)



Both values must be dates and not null for the function to do it's thing.

Note, hour and hh are the same.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1