Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL - How to compare 2 time values in varchar?

Posted on 2008-10-30
2
Medium Priority
?
392 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 1000 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 1000 total points
ID: 22845819
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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 ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.

721 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