1个SQL Server的日期时间转换错误,但另一个不存在 [英] Datetime conversion error for 1 sql server, but not another

查看:79
本文介绍了1个SQL Server的日期时间转换错误,但另一个不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2台运行SQL Server 2008的服务器,并且有以下查询:

I've got 2 servers running SQL Server 2008, and I have the following query:

SELECT cast('13/1/2011' as datetime)

如果我在服务器A上执行此查询我得到结果:

2011-01-13 00:00:00.000

但是,如果我在服务器B 上执行此操作,则会得到结果:

However, if I execute this on Server B I get the result:


将varchar数据类型转换为日期时间数据类型会导致
超出范围。

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

我认为这是英国/美国日期格式的问题,因为在 12/1/2011 但它确实返回 2011-12-01 00:00:00.000

I believe this to be a UK/US date format issue as I don't get an error with 12/1/2011 but it does return 2011-12-01 00:00:00.000

如何获取服务器B 获得与服务器A 相同的结果?

How can I get Server B to get the same result as Server A? What setting needs to be changed and where?

推荐答案

这是登录的语言设置 code>控制如何解释这些不明确的日期格式(尽管可以使用显式的 SET DATEFORMAT 语句覆盖)。

It is the language setting of the login that controls how these ambiguous date formats are interpreted (though this can be overridden with an explicit SET DATEFORMAT statement).

DEFAULT_LANGUAGE 可以通过 更改登录

The DEFAULT_LANGUAGE can be changed via ALTER LOGIN

这篇关于1个SQL Server的日期时间转换错误,但另一个不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆