在脚本中使用T-SQL“两位数年截止日期”

时间:2023-01-06 08:36:29

I'm writing a script to cleanup some data, converting dates stored in an varchar field from dd/mm/yy to dd/mm/yyyy format. (yes, I know, but not my design :)

我正在编写一个脚本以清理一些数据,将存储在varchar字段中的日期从dd/mm/yy转换为dd/mm/yyyy格式。(是的,我知道,但不是我的设计:)

I've got a script written to do this, but I've currently got a hardcoded constant of 2049 as the cutoff date. I know SQL has a 'Two Digit Year Cutoff' advanced option, which I'd like to use in place of this constant.

我已经编写了一个脚本来实现这一点,但是我现在有一个硬编码常量2049作为截止日期。我知道SQL有一个“两位数年截止”的高级选项,我想用它来代替这个常量。

Is there a safe/convenient way to retrieve and use this in a script? (Needs to support SQL-Server 2005/2008/2008R2)

是否有一种安全/方便的方法在脚本中检索和使用它?(需要支援SQL-Server 2005/2008/2008R2)

1 个解决方案

#1


4  

SELECT value
FROM sys.configurations 
WHERE name = 'two digit year cutoff'

But can't you just convert (assuming that your system is setup to use dd/mm/yyy as a standard) to a datetime, and then back again?

但是,您难道不能将(假设您的系统设置为使用dd/mm/yyy作为标准)转换为datetime,然后再返回吗?

#1


4  

SELECT value
FROM sys.configurations 
WHERE name = 'two digit year cutoff'

But can't you just convert (assuming that your system is setup to use dd/mm/yyy as a standard) to a datetime, and then back again?

但是,您难道不能将(假设您的系统设置为使用dd/mm/yyy作为标准)转换为datetime,然后再返回吗?