Solved

SQL - How to compare 2 time values in varchar?

Posted on 2008-10-30
2
388 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

697 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