Solved

Get time in hours from start time and end time MSSQL

Posted on 2016-07-27
7
32 Views
Last Modified: 2016-08-22
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
Comment
Question by:meldraper
  • 3
  • 2
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41731722
SELECT DATEDIFF(hour, pdsStartTime, pdsEndTime) as hours_diff
FROM programDaySchedule

Open in new window

1
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points (awarded by participants)
ID: 41731726
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
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41731727
Select the dateDiff in hours:

select DATEDIFF(HOUR,pdsStartTime,pdsEndTime) from programDaySchedule

Open in new window

0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41731729
Oops, stepped on your toes Jimbo!
0
 

Author Comment

by:meldraper
ID: 41731738
Thank you Jimbo.  That's exactly what I needed.  It works great.
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41756104
First working answer.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now