Solved

Get time in hours from start time and end time MSSQL

Posted on 2016-07-27
7
37 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 66

Expert Comment

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

Open in new window

1
 
LVL 66

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 13

Expert Comment

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

select DATEDIFF(HOUR,pdsStartTime,pdsEndTime) from programDaySchedule

Open in new window

0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 13

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 13

Expert Comment

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

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

724 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