user392597
user392597

Reputation: 1

How to get the time in hours between these two dates

I have one table in that they are four columns 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.

Upvotes: 0

Views: 710

Answers (3)

Chris Van Opstal
Chris Van Opstal

Reputation: 37537

You're looking for the DATEDIFF function:

SELECT DATEDIFF(hh, startdate, enddate)

Upvotes: 0

DaveShaw
DaveShaw

Reputation: 52788

Use the SQL DateDiff function.

Upvotes: 1

Andomar
Andomar

Reputation: 238068

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

Upvotes: 2

Related Questions