Created
October 22, 2012 03:07
-
-
Save sinairv/3929434 to your computer and use it in GitHub Desktop.
Convert a decimal number to a 'hh:mm' formatted hour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- how to convert a decimal number to a 'hh:mm' formatted hour. E.g., | |
-- 2.25 -> 02:15 | |
-- 13.5 -> 13:30 | |
-- 2.10 -> 02:06 | |
DECLARE @Value DECIMAL(18,2) = 2.10; | |
SELECT RIGHT('00' + | |
CONVERT(VARCHAR, CONVERT(INT, @Value)), 2) | |
+ ':' + | |
RIGHT('00' + | |
CONVERT(VARCHAR, | |
CONVERT(INT, | |
ROUND((@Value - CONVERT(INT, @Value)) * 60, 0, 0))), 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment