MySQL: Digits (1.75) to Friendly Time (1 hour and 45 minutes)
Posted
by
Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2010-12-21T19:29:40Z
Indexed on
2010/12/21
19:54 UTC
Read the original article
Hit count: 174
mysql
In my MySQL database, I have a float field named "HoursSpent" with values like "0.25", "1.75", "2.5", etc. Is there a way that I can have my SELECT statement format those values in a friendly format like this?:
0.25 = 15 minutes
1.75 = 1 hour and 45 minutes
2.5 = 2 hours and 30 minutes
The "HoursSpent" field is supposed to only have values in 0.25 increments, but if somebody were to put something random like 0.16, it would be nice if the SELECT statement handled that by rounding it up to the nearest 0.25 (so in this case 0.16 would become 0.25, or 15 minutes).
© Stack Overflow or respective owner