Reputation: 307
How can I convert string with format dddd mm/dd/yy
to date in SQL Server?
e.g. Wednesday 1/9/13
Upvotes: 2
Views: 1210
Reputation: 1269453
Once you eliminate the day of the week, you can just convert the rest of the value.
The following works:
select cast(right(col, len(col) - charindex(' ', col)) as date)
from (select 'Wednesday 1/9/13' as col) t;
EDIT:
Aaron makes a good point. You can ensure the conversion by using convert
with a style of "1":
select convert(date, right(col, len(col) - charindex(' ', col)) , 1)
from (select 'Wednesday 1/9/13' as col) t;
(101 doesn't work because it expects a 4-digit year.)
Upvotes: 3