Home Forums SQL Server 2014 Administration - SQL Server 2014 Trying to convert varchar to datetime RE: Trying to convert varchar to datetime
savycara
Old Hand
Points: 398
More actions
July 24, 2013 at 9:31 am
#1635413
DECLARE @d varchar(6) = '20114'
SELECT try_convert(date, substring(@d, 1, 4) +
CASE WHEN len(@d) = 5 THEN '0' ELSE '' END +
substring(@d, 5, 2) + '01')
This worked but I am not getting in 101 style that is 04/01/2011