Been struggling with this and can\'t seem to find the right answer, although there are plenty of mentions for converting, but nothing specific is working.
I need to
You can try:
DECLARE @HOURS decimal(7,4) = 20.5599
SELECT CAST(CONVERT(VARCHAR,DATEADD(SECOND, @HOURS * 3600, 0),108) AS TIME)
output : 20:33:35
But remember : Type Time in MSSQL only under 24hrs
If you want greater than 24hrs, try:
DECLARE @HOURS decimal(7,4) = 25.5599
SELECT
RIGHT('0' + CAST (FLOOR(@HOURS) AS VARCHAR), 2) + ':' +
RIGHT('0' + CAST(FLOOR((((@HOURS * 3600) % 3600) / 60)) AS VARCHAR), 2) + ':' +
RIGHT('0' + CAST (FLOOR((@HOURS * 3600) % 60) AS VARCHAR), 2)
output : 25:33:35
-- Update
Decimal minutes to more than 24hrs
DECLARE @MINUTES decimal(7,4) = 77.9
SELECT
RIGHT('0' + CAST (FLOOR(COALESCE (@MINUTES, 0) / 60) AS VARCHAR (8)), 2) + ':' +
RIGHT('0' + CAST (FLOOR(COALESCE (@MINUTES, 0) % 60) AS VARCHAR (2)), 2) + ':' +
RIGHT('0' + CAST (FLOOR((@MINUTES* 60) % 60) AS VARCHAR (2)), 2);
output: 01:17:54
DECLARE @f FLOAT = 13.5;
SELECT CONVERT(TIME(0), DATEADD(MINUTE, 60*@f, 0));
Or if you just want hh:mm
as a string:
SELECT CONVERT(CHAR(5), DATEADD(MINUTE, 60*@f, 0), 108);
Just be careful if you have values >= 24.
This should work for you
DECLARE @f [real]
SET @f = 13.50
SELECT DATEADD(mi, (@f - FLOOR(@f)) * 60, DATEADD(hh, FLOOR(@f), CAST ('00:00:00' AS TIME)))
How about you convert to minutes and add to the 00:00 time like so:
DECLARE @c datetime
select @c = dateadd(mi,fdsViewTimesheet.perStandardHours*60,'00:00')
If you wanted to do it in the statement with Time only:
select CONVERT(TIME,dateadd(mi,fdsViewTimesheet.perStandardHours*60,'00:00') )
If you have values that are larger than 24 hours, then the standard datetime and time types in sql cannot hold these. They are limited to holding 24 hour ranges. What you would need to do is store the time representation in a string for example like so:
select cast(floor(fdsViewTimesheet.perStandardHours) as varchar(10)) + ':' + cast(FLOOR( (fdsViewTimesheet.perStandardHours - floor(fdsViewTimesheet.perStandardHours))*60)as varchar(2))