Sql Query to show minutes as HH:MM but with time datatype

I have sql query where i am converting minutes to HH:MM format by using this query

declare @tempt table(col1 int)
insert into @tempt  
select 140
union all
select 35
select cast (cast((col1)/60 as varchar)   
 + ':' + RIGHT('0' + cast((col1)%60 as varchar),2) as Time) Running
  from @tempt

and output is

Running
02:20:00.0000000
00:35:00.0000000

But i want to show as 02:20 and 00:35 .

How do i eliminate these rest of zero's ?

Answers


We can cast it like this,

SELECT CONVERT(VARCHAR(5),getdate(),108) 

replace getdate() with your datetime object


This will give you the result in Time datatype, in hh:mm:ss format

declare @tempt table(col1 int)
insert into @tempt  
select 140
union all
select 35
select cast (cast((col1)/60 as varchar)   
 + ':' + RIGHT('0' + cast((col1)%60 as varchar),2) as Time(0)) Running
  from @tempt

Need Your Help

reorder the div vertically in small screen using twitter bootstrap

jquery html css twitter-bootstrap

On the mobile template i want to position the contact widget at first inside the sidebar. Please check this example. Is there any way to do that