如何将格式为 dddd mm/dd/yy
的字符串转换为 SQL Server 中的日期?
例如2013 年 1 月 9 日星期三
最佳答案
一旦消除了星期几,您就可以转换其余的值。
以下作品:
select cast(right(col, len(col) - charindex(' ', col)) as date)
from (select 'Wednesday 1/9/13' as col) t;
编辑:
亚伦说得很好。您可以使用样式为“1”的 convert
来确保转换:
select convert(date, right(col, len(col) - charindex(' ', col)) , 1)
from (select 'Wednesday 1/9/13' as col) t;
(101 不起作用,因为它需要 4 位数的年份。)
关于SQL Server : convert string with format dddd mm/dd/yy to date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18116346/