Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2006-06-21 : 11:38:28
|
| How in SQL can I convert8,079999 hours into 8:05 (8 hours and 5 minutes)HenriHenri~~~~The envious praises me unknowingly |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-06-21 : 11:52:42
|
You can use something along the lines of...--inputdeclare @x decimal(18, 6)set @x = 8.079999--calculationselect left(convert(varchar, dateadd(minute, round(@x * 60, 0), 0), 108), 5)/*results08:05*/ Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2006-06-21 : 12:02:18
|
| You should get a reward for this! Brilliant!Henri~~~~The envious praises me unknowingly |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-06-21 : 12:14:02
|
You can buy me a beer sometime... Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2006-06-27 : 10:15:15
|
Hmm, the solution has a 24 hrs assumption.I made a function for the minutes to hour notation.ALTER FUNCTION [dbo].[fnMinutesToTime] ( @Minutes AS int)RETURNS varchar(5)ASBEGIN DECLARE @Result varchar(5), @Hours int, @Reminder int SELECT @Hours = @Minutes / 60, @Reminder = @Minutes % 60 SELECT @Result = CASE WHEN @Hours < 10 THEN '0' ELSE '' END + CAST(@Hours AS varchar(2)) + ':' + CASE WHEN @Reminder < 10 THEN '0' ELSE '' END + CAST(@Reminder AS varchar(2)) RETURN @ResultEND Henri~~~~The envious praises me unknowingly |
 |
|
|
|
|
|
|
|