在SQL Server中的单个数据库上更改默认日期时间格式 [英] Change default date time format on a single database in SQL Server

查看:155
本文介绍了在SQL Server中的单个数据库上更改默认日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在SQL服务器机器上的单个数据库上将日期格式从美国(mm / dd / YYYY)更改为英国(dd / mm / YYYY)。



如何才能完成?



我已经看到为整个系统执行此操作的语句,以及为会话执行此操作的语句,但是我可以'现在更改代码,因为它必须再次通过质量检查,所以我需要一个快速修复来更改日期时间格式。



更新



我意识到日期时间与SQL Server如何存储数据无关,但与解析查询的方式有很大的关系。 p>

我将原始数据从XML文件夹入数据库。 XML文件中的日期是英国的日期格式。

解决方案

您可以使用 SET DATEFORMAT 像这样的例子

  declare @dates table(orig varchar(50),parsed datetime)

SET DATEFORMAT ydm;

insert into @dates
select'2008-09-01','2008-09-01'

SET DATEFORMAT ymd;
insert into @dates
select'2008-09-01','2008-09-01'

select * from @dates

解析XML数据时,需要在代码中指定dateformat


I need to change the date format from US (mm/dd/YYYY) to UK (dd/mm/YYYY) on a single database on a SQL server machine.

How can this be done?

I've seen statements that do this for the whole system, and ones that do it for the session, but I can't change the code now as it will have to go through QA again, so I need a quick fix to change the date time format.

Update

I realize that the date time has nothing to do with how SQL Server stores the data, but it does have a lot to do with how it parses queries.

I'm chucking raw data from an XML file into a database. The dates in the XML file are in UK date format.

解决方案

You could use SET DATEFORMAT, like in this example

declare @dates table (orig varchar(50) ,parsed datetime)

SET DATEFORMAT ydm;

insert into @dates
select '2008-09-01','2008-09-01'

SET DATEFORMAT ymd;
insert into @dates
select '2008-09-01','2008-09-01'

select * from @dates

You would need to specify the dateformat in the code when you parse your XML data

这篇关于在SQL Server中的单个数据库上更改默认日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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