SQL convert 'DDMMYY' to datetime

后端 未结 3 1280
野趣味
野趣味 2020-12-11 18:14

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

I am using the convert command as follows

相关标签:
3条回答
  • 2020-12-11 18:42
    select CAST('121031' AS datetime)  as d -- For YYMMDD
    
    0 讨论(0)
  • 2020-12-11 18:53
    select convert (datetime,  Stuff(Stuff('311012',5,0,'.'),3,0,'.'), 4)
    
    0 讨论(0)
  • 2020-12-11 18:59

    Try like this :-

    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 讨论(0)
提交回复
热议问题