Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 42
  • Last Modified:

Get time in hours from start time and end time MSSQL

I have a table with two time columns and I need to get the number of hours from the start time and end time.  I'm absolutely blank.  Any help would be appreciated.  many thanks in advance.  It is a simple table, example below.

Select pdsStartTime, pdsEndTime from programDaySchedule

Open in new window

0
meldraper
Asked:
meldraper
  • 3
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
SELECT DATEDIFF(hour, pdsStartTime, pdsEndTime) as hours_diff
FROM programDaySchedule

Open in new window

1
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The above just takes the hours.  A more precise answer would be to get the difference in minutes and divide by 60.

SELECT DATEDIFF(minute, pdsStartTime, pdsEndTime) / 60.0
FROM programDaySchedule

Open in new window

1
 
Dustin SaundersDirector of OperationsCommented:
Select the dateDiff in hours:

select DATEDIFF(HOUR,pdsStartTime,pdsEndTime) from programDaySchedule

Open in new window

0
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
Dustin SaundersDirector of OperationsCommented:
Oops, stepped on your toes Jimbo!
0
 
meldraperAuthor Commented:
Thank you Jimbo.  That's exactly what I needed.  It works great.
0
 
Dustin SaundersDirector of OperationsCommented:
First working answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now