September 28, 2010 at 9:37 am
I'm currently using convert("duration",108) to display a duration of time in seconds (field is defined as a INT) as hh:mm:ss. It works fine but the customer wants to see the value in mm:ss - and I can't seem to find the right code.
Anyone have a quick fix off hand?
September 28, 2010 at 9:58 am
i think it's just a combination of integer division and modulus:
/*--results
MinutesSeconds
2571
210
*/
--example where value is an integer of seconds
SELECT intSeconds / 60 as [Minutes],
intSeconds % 60 as [Seconds]
FROM
(SELECT 15421 AS intSeconds UNION ALL
SELECT 130 ) X
Lowell
September 29, 2010 at 9:50 am
Not quite was I was looking for.
The convert function specifying 108 (as above) outputs the time duration as hh:mm:ss.
I'm looking for a function that would output mm:ss. Specifically drop the hh: part.
September 29, 2010 at 11:06 am
--supply a date or getdate(), etc
declare @dtime datetime
select @dtime = '2010-07-04 10:25:21'
--pick out the parts you need
select cast(datepart(mi, @dtime) as varchar(2)) + ':' +
cast(datepart(ss, @dtime) as varchar(2))
Returns
25:21
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
September 29, 2010 at 12:36 pm
Using Perrys sample:
SELECT RIGHT(CONVERT(CHAR(8),@dtime,8),5)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply