如何将默认系统日期从 ymd 更改为 dmy [英] How to change default systemdate from ymd to dmy

查看:46
本文介绍了如何将默认系统日期从 ymd 更改为 dmy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我将默认的 systemdate 从 ymd 更改为 dmy 吗?这些必须始终是默认格式!怎么样?

Can somebody help me to change the default systemdate from ymd to dmy? These must be for always the default format !! How?

推荐答案

SET DATEFORMAT:

设置月份、日期和日期的顺序用于解释日期的年份日期部分,smalldatetime、datetime、datetime2 和datetimeoffset 字符串.

Sets the order of the month, day, and year date parts for interpreting date, smalldatetime, datetime, datetime2 and datetimeoffset character strings.

[注意:这通常不是解决日期解释问题的方法.如果可以避免,则不应将日期时间存储为字符串(改为使用日期时间或日期列).如果您必须以字符串形式存储,请使用 ISO 8601 格式,该格式基本上是 YYYYMMDD ]

[Note: This is often not the way to solve the problem of interpreting dates. Datetimes should not be stored a strings if you can avoid it (use a datetime or date column instead). If you have to store in a string form, use an ISO 8601 format which is basically of the form YYYYMMDD ]

来自 MSDN 的示例:

Example from MSDN:

-- Set date format to day/month/year.
SET DATEFORMAT dmy;
GO
DECLARE @datevar datetime2 = '31/12/2008 09:01:01.1234567';
SELECT @datevar;
GO
-- Result: 2008-12-31 09:01:01.123
SET DATEFORMAT dmy;
GO
DECLARE @datevar datetime2 = '12/31/2008 09:01:01.1234567';
SELECT @datevar;
GO
-- Result: Msg 241: Conversion failed when converting date and/or time -- from character string.
GO

这篇关于如何将默认系统日期从 ymd 更改为 dmy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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