Parse a date from unformatted text in SQL

前端 未结 4 1498
执笔经年
执笔经年 2020-12-11 02:44

I\'m trying to figure out an elegant way to get a date from a text column that has data like this \"YYYYMMDD\"...so we might see \"20060508\" as a value in the column, which

4条回答
  •  失恋的感觉
    2020-12-11 03:34

    No sweat, just CONVERT it. Style "112", or ISO would handle your example case.

    SELECT CONVERT(datetime,'20060508',112)
    

    returns

     ----------------------- 2006-05-08 00:00:00.000
    
     (1 row(s) affected)
    

提交回复
热议问题