I have run into a SQL snippet including date conversion with 6 digits in the format of YYMMDD.
SELECT CONVERT(DATETIME, '6011' + '01') AS testingdate
Why doesn't the followed query yield 2060-11-01 while '2011' + '01' yields 2020-11-01?
I have run into a SQL snippet including date conversion with 6 digits in the format of YYMMDD.
SELECT CONVERT(DATETIME, '6011' + '01') AS testingdate
Why doesn't the followed query yield 2060-11-01 while '2011' + '01' yields 2020-11-01?
Copyright © 2021 Jogjafile Inc.
As @Squirrel commented, behavior for interpreting ambiguous 2-digit years is controlled by the 2 digit year cut-off configuration value. The value specifies an integer from 1753 to 9999 that represents the cutoff year for interpreting two-digit years as four-digit years, with a default configuration value of 2049.
The code below shows the behavior with default and custom 2 digit year cut-off values.
2-digit year cut-off is a kludge work-around for short-sighted programming practices of the past, IMHO. I suggest one follow the recommendation from the referenced documentation page so that ancestors don't inherit a Y2.1K problem: