Skip to content

Instantly share code, notes, and snippets.

@sinairv
Created October 22, 2012 03:07
Show Gist options
  • Save sinairv/3929434 to your computer and use it in GitHub Desktop.
Save sinairv/3929434 to your computer and use it in GitHub Desktop.
Convert a decimal number to a 'hh:mm' formatted hour
-- 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