views:

36

answers:

3

Hi Guys,

I have one table in that they are four coumns like

startdate varchar(15),
enddate varchar(15),
starttime varchar(15),
endtime varchar(15)

Here I need to get the time in hours between these two dates (ex: 6/7/2010,6/12/2010) if i pass these days as inputs

regards, ravi

+2  A: 

It's usually as simple as:

select datediff(hour, starttime, endtime)

For example:

select datediff(hour, '2010-01-01 12:00', '2010-01-02 13:45')

Prints:

25
Andomar
I think you have the endtime and starttime parameters the wrong way around! This will return a negative value, which is probably not correct given the way the question is worded.
barrylloyd
thanx barry .but here i am using two dates as inputs parameters and i need to get time as output
+1, you could even do this like `select datediff(minute, '2010-01-01 12:00', '2010-01-02 13:45')/60.0` and still get hours, but with more precision: `25.750000`
KM
+1  A: 

Use the SQL DateDiff function.

DaveShaw
A: 

You're looking for the DATEDIFF function:

SELECT DATEDIFF(hh, startdate, enddate)
Chris Pebble