[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1186
  • Last Modified:

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

0
Rick
Asked:
Rick
  • 3
  • 2
1 Solution
 
gregfortuneCommented:
select hour(timediff(EndTime, StartTime)), round(minute(timediff(EndTime, StartTime))/60, 1);
0
 
gregfortuneCommented:
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
 
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now