我在Varchar中有一个字符串Sunday, November 19, 2017
。
如何将其转换为日期格式 - dddd, MMMM, yyyy
?
答案 0 :(得分:0)
你在找这个:
DECLARE @MyDate VARCHAR(32) = 'Sunday, November 19, 2017';
SELECT CONVERT(VARCHAR(32), CAST(SUBSTRING(@MyDate, CHARINDEX(',', @MyDate) + 2, 32) AS DATETIME2), 105); -- 19-11-2017
或者这个:
SELECT FORMAT(CAST(SUBSTRING(@MyDate, CHARINDEX(',', @MyDate) + 2, 32) AS DATETIME2), 'dddd, MMMM, yyyy'); -- Sunday, November, 2017