tsql - How to convert from varchar/numeric to Time in SQL server -


i have table time field datatype numeric(6,0) , showing 24 hour format 100,150300,21000 etc.

here 100->00:01:00 (12:01am) wrote store varchar missing 0's before:

select right('000000'+ cast(fm_time varchar(6)),6) ft_time table; 

now how convert field time show in 12 hour format or pm.

can convert directly numeric time adding leading 0's?

if @ possible should update column time datatype instead of numeric(6,0).

this works sample data provided. careful though, may have values in table invalid.

create table #something (     fm_time numeric(6,0) )  insert #something select 100 union select 150300 union select 21000   select convert(varchar(15), convert(time, stuff(stuff(right(replicate('0', 6) + convert(varchar(6), fm_time), 6), 3, 0, ':'), 6, 0, ':')), 100) #something  drop table #something 

Comments