有帮助吗?

解决方案

There is no method to directly convert this value because SQL implicitly assumes the first two characters are the year when directly converting to DATE and there is no option for providing a custom format mask.

You need to manipulate the string value first to produce a string that you can then convert to a datetime value.

DECLARE @Val VARCHAR(25) = '060118'

SELECT CONVERT(DATETIME, SUBSTRING(@Val, 5, 2) + SUBSTRING(@Val, 1, 2) + SUBSTRING(@Val, 3, 2) , 101)

Result:
06/01/2018

CAST and CONVERT

SUBSTRING

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top