question

faxmonkey avatar image
faxmonkey asked

Trying to convert a Varchar(6) to time data stored as hhmmss

I have a nvarchar(6) column which holds time. Such as 153000 for 3:30:00 (hhmmss).

Tried the convert 8, 108 but that doesn't seem to do a thing.

sql query
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
declare @x as nvarchar(6)
set @x = '153000'


select timefromparts(
	left(right('000000'+@x,6),2),
	left(right(right('000000'+@x,6),4),2),
	right(right('000000'+@x,6),2)
	,0,0)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.