MySql 5.1 - Show time difference between two columns

Hello,

How do I write a SELECT statement to show the time difference between two columns.
I want to show the difference in Double type, not in Time.
Example:
 
StartTime      EndTime
 
08:30:00       10:00:00
 
 
I want to show the result as 1.5, not 01:30:00
 
 
Thanks,
Rick

Open in new window

LVL 13
RickAsked:
Who is Participating?
 
gregfortuneConnect With a Mentor Commented:
Hmm, guess I can't edit my first post.  If you want that as a single value, you'd just add the two results together.

For example,

hour(timediff(EndTime, StartTime)) + round(minute(timediff(EndTime, StartTime))/60, 1)
0
 
gregfortuneCommented:
select hour(timediff(EndTime, StartTime)), round(minute(timediff(EndTime, StartTime))/60, 1);
0
 
RickAuthor Commented:
gregfortune,

That's really good. Thanks.
I will accept your answer, I just have one question though, what's the "1" at the end of the query?


Thanks,
Rick
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
suredazzleCommented:


For example, 1 means 45.923 = 45.9
0
 
gregfortuneCommented:
Yup, as suredazzle stated, round takes two arguments.  The first argument is the number to round and the second argument is the "precision" or number of digits after the dot.  If you want two digits (ie, 123.01), change it from 1 to 2.
0
 
RickAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.