Solved

SQL - How to compare 2 time values in varchar?

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

856 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