| Author |
Topic |
|
NEVerton
Starting Member
9 Posts |
Posted - 2011-09-13 : 18:15:49
|
| I need to convert a number of minutes into HH:MM format, e.g. 360 = 06:00, 15 = 00:15, 1440 = 24:00, 2160 = 36:00Heeeelp! I'm going insane after numerous attempts to achieve this!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
flamblaster
Constraint Violating Yak Guru
384 Posts |
Posted - 2011-09-13 : 20:07:23
|
| You could also do this, though it has the leading 00: before the minutes part:[CODE]CONVERT(CHAR(8), DATEADD(MINUTE, (@i/ 60.0), 0), 8)[/CODE] |
 |
|
|
flamblaster
Constraint Violating Yak Guru
384 Posts |
Posted - 2011-09-13 : 20:10:05
|
| nix that, doesn't work for less than 1 minute. Back to the drawing board! |
 |
|
|
flamblaster
Constraint Violating Yak Guru
384 Posts |
Posted - 2011-09-13 : 20:17:40
|
| ---Forgot to paste the declare/set on the first post. Kinda important :p[CODE]declare @i int ,@H int ,@M int ,@S intselect @i = 30select @H=@i/3600select @M=(@i % 3600) / 60select @S=(@i % 3600) % 60SELECT CONVERT(time, convert(char(2), @h)+':'+convert(char(2),@m)+':'+convert(char(2), @s),8)[/CODE] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-14 : 00:16:09
|
| [code]DECLARE @minute intSET @minute=534SELECT CONVERT(varchar(5),DATEADD(minute,@minute,0),108)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
NEVerton
Starting Member
9 Posts |
Posted - 2011-09-14 : 02:20:25
|
Sorry all, forgot to mention that the minutes returned could also be negative, i.e. -15 = -00:15, -360 = -06:00Thanks!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-14 : 03:35:24
|
DECLARE @minute intSET @minute=534SELECT CASE WHEN SIGN(@minute) = -1.0 THEN '-' ELSE '' END + CONVERT(varchar(5),DATEADD(minute,ABS(@minute),0),108) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
NEVerton
Starting Member
9 Posts |
Posted - 2011-09-14 : 08:41:54
|
| Unfortunately, this doesn't work for minutes equivalent to 1 day or more =, i.e. > 1440SELECT CASE WHEN SIGN(@minute) = -1.0 THEN '-' ELSE '' END + CONVERT(varchar(5),DATEADD(minute,ABS(@minute),0),108) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-14 : 08:50:51
|
| [code]SELECT CASE WHEN SIGN(@minute) = -1.0 THEN '-' ELSE '' END + CONVERT(varchar(10),ABS(@minute)/60) + ':' + CONVERT(varchar(10),ABS(@minute)%60)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|