SQL converts 'DDMMYY' to datetime

I am trying to convert a date from DDMMYY to datetime format in SQL Server.

I use the convert command as follows

 select convert (datetime, '311012', <style>) 

I tried looking for msdn for supported styles, but did not find an exact match.

Help would be greatly appreciated.

+4
source share
3 answers
 select convert (datetime, Stuff(Stuff('311012',5,0,'.'),3,0,'.'), 4) 
+10
source

Try the following: -

 declare @val1 varchar(30) select @val1=SUBSTRING('311012',1 ,2)+'/'+SUBSTRING('311012',3 ,2)+'/'+'20'+SUBSTRING('311012',5 ,2) SELECT CONVERT(datetime,@val1,103) 
0
source
 select CAST('121031' AS datetime) as d -- For YYMMDD 
0
source

Source: https://habr.com/ru/post/1447723/


All Articles