Solved

SQL - How to compare 2 time values in varchar?

Posted on 2008-10-30
2
384 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
2 Comments
 
LVL 59

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

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.

Join & Write a Comment

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

747 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

9 Experts available now in Live!

Get 1:1 Help Now