Solved

SQL - How to compare 2 time values in varchar?

Posted on 2008-10-30
2
390 Views
Last Modified: 2012-05-05
I have a table1 containing the following fields:
StartHour int
StartMinute int
EndHour int
EndMinute int

so if an event started at 2:30 and ended at 3:00, the table would have values:
StartHour = 2
StartMinute = 30
EndHour = 3
EndMinute = 0

I want to be able to get the difference between start time and end time:
diff(2:30, 3:00)

Suggestions?
Thx.
0
Comment
Question by:fippif
[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
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 250 total points
ID: 22845810
Since your data is stored in integers, I would just do simple math in minutes.

SELECT (EndHour * 60 + EndMinute) - (StartHour * 60 + StartMinute)  AS DiffTimes
FROM Table1
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 250 total points
ID: 22845819
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

634 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