Convert hh:mm:ss to hh:mm in SQL Server -


i have time 04:02:00, want 4:02 using sql server

i have tried code:

@time time set @time ='04:02:00'   select right(convert(varchar, @time, 100), 8) 

it produces output:

4:02am 

please ..

thanks

you can use datepart , concatenate there:

select      right('00' + convert(varchar(2), datepart(hour, @time)), 2) + ':'       + right('00' + convert(varchar(2), datepart(minute, @time)), 2) 

notice right('00' + ..., 2), pad hour or minute part leading zeroes it'll 2 characters long, e.g 4 becomes 04.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -