如何从字符串转换日期/时间
,CONVERT(VARCHAR(10), RegistrationCreatedDate, 10) AS 'Date Submitted'
,CONVERT(VARCHAR(10), StatusUpdatedDate, 10) AS 'Current Status Date'
,CONVERT(VARCHAR(10), CONVERT(DATETIME, CONVERT(DATETIMEOFFSET, [AcceptedDate])), 10) AS 'Date Accepted'
, PaymentAuthID
, PaymentAmount
FROM (
SELECT R.RegistrationGUID
,CAST(RR.ShortResponseValue AS VARCHAR(MAX)) AS ResponseValue
,RR.QuestionShortCode
,R.ApplicationGUID
,R.RegistrationUpdatedDate
,XRSH.StatusUpdatedDate
,OD.ResponseValue AS PaymentAuthID
,CD.ResponseValue AS PaymentAmount
,APS.STATUSNAME
,O.OrderGUID
,[RegistrationCreatedDate]
我在这一行有错误:
,CONVERT(VARCHAR(10), CONVERT(DATETIME, CONVERT(DATETIMEOFFSET, [AcceptedDate])), 10) AS 'Date Accepted'
错误是:
从字符串转换日期和/或时间时转换失败。
答案 0 :(得分:0)
试试这样:
SELECT CONVERT(VARCHAR(10), CONVERT(DATETIME, CONVERT(DATETIMEOFFSET, [NameColumn])), 10) AS 'Date Accepted'
FROM [NameTable]