问题
The dates are currently displayed as: ddmmmyyyy
(12DEC2013)
I've been playing around with this formula:
DECLARE @Date char(8)
set @Date='12312009'
SELECT CONVERT(datetime,RIGHT(@Date,4)+LEFT(@Date,2)+SUBSTRING(@Date,3,2))
but I didn't have any success, can someone help me out with this. Additionally all my dates are in a column called TERMDT
and I'd like to put all the new date values in a new column formatted as such.
回答1:
Just give convert()
an appropriate 3rd argument (the format):
SELECT CONVERT(datetime,
RIGHT(d, 4) + LEFT(d,2) + SUBSTRING(d, 3, 2),
112)
from (select '12312009' as d) t
来源:https://stackoverflow.com/questions/25727125/i-have-a-column-of-dates-in-varchar-and-i-need-to-convert-to-date