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 |
nevzab
Starting Member
34 Posts |
Posted - 2013-06-20 : 17:33:46
|
I need to convert minutes into HH:MM. For example:60 = 01:0065 = 01:0570 = 01:10100 = 01:40120 = 02:002880 = 48:002945 = 49:05What is the simplest way to do this?Cheers,Nev. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-06-20 : 17:52:57
|
May not be the simplest, but here is an example of one way to do this:DECLARE @x INT = 2945;SELECT @x/60, @x%60, RIGHT('00'+CAST(@x/60 AS VARCHAR(8)),2)+':'+RIGHT('00'+CAST(@x%60 AS VARCHAR(8)),2) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 02:10:39
|
[code]SELECT CAST((DATEDIFF(dd,0,dateval) *24 + DATEPART(hh,dateval)) AS varchar(3)) + ':' + DATENAME(minute,dateval)FROM (SELECT DATEADD(minutes,yourfield,0) AS dateval FROM table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
nevzab
Starting Member
34 Posts |
Posted - 2013-06-24 : 17:44:53
|
Guys, I forgot to thank you your answers. Genius!! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-25 : 00:38:10
|
no problemyou're welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2013-06-25 : 02:09:36
|
Visakh - since our discussion on some other thread last week about datetime functions wrt allowing any indexes to still be used, you have converted me to use these datetime calculations as much as possible as opposed to MONTH and Year type functions.I had never given this side of sql any thought until you pointed this out to me.Thanks again.Duane.http://ditchiecubeblog.wordpress.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-25 : 02:16:43
|
quote: Originally posted by ditch Visakh - since our discussion on some other thread last week about datetime functions wrt allowing any indexes to still be used, you have converted me to use these datetime calculations as much as possible as opposed to MONTH and Year type functions.I had never given this side of sql any thought until you pointed this out to me.Thanks again.Duane.http://ditchiecubeblog.wordpress.com/
No problemGlad that my post could be of help to you ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|