SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Converting minutes into HH:MM
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nevzab
Starting Member

United Kingdom
34 Posts

Posted - 06/20/2013 :  17:33:46  Show Profile  Reply with Quote
I need to convert minutes into HH:MM.

For example:

60 = 01:00
65 = 01:05
70 = 01:10
100 = 01:40
120 = 02:00
2880 = 48:00
2945 = 49:05

What is the simplest way to do this?

Cheers,

Nev.

James K
Flowing Fount of Yak Knowledge

3719 Posts

Posted - 06/20/2013 :  17:52:57  Show Profile  Reply with Quote
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)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/21/2013 :  02:10:39  Show Profile  Reply with Quote

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

nevzab
Starting Member

United Kingdom
34 Posts

Posted - 06/24/2013 :  17:44:53  Show Profile  Reply with Quote
Guys, I forgot to thank you your answers. Genius!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/25/2013 :  00:38:10  Show Profile  Reply with Quote
no problem
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ditch
Flowing Fount of Yak Knowledge

South Africa
1466 Posts

Posted - 06/25/2013 :  02:09:36  Show Profile  Visit ditch's Homepage  Reply with Quote
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/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/25/2013 :  02:16:43  Show Profile  Reply with Quote
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 problem
Glad that my post could be of help to you

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000