Solved

Get time in hours from start time and end time MSSQL

Posted on 2016-07-27
7
33 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with SQL Server Polygon 2 32
insert into table 8 22
SSRS 2013 - Creating a summarized report 19 32
SSRS Enable Remote Errors 4 22
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

813 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

11 Experts available now in Live!

Get 1:1 Help Now