在SQL Server中更改日期格式 [英] Change date format in sql server
本文介绍了在SQL Server中更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的sql server中,日期格式类似于"dd/mm/yyyy".但是我想更改英国格式``mm/dd/yyyy''.如何更改.
请帮助我
解决方案
您不知道.你不能将DateTime转换为特定格式的唯一方法是将其转换为VARCHAR或其他字符串"数据类型.这意味着它不再是DateTime.这是一个VARCHAR.
以下是要转换为"mm/dd/yyyy"格式的代码:
选择 正确(' 0' + rtrim(month( @ d )),' 正确( 0' + rtrim(day( 2 )+ /' + rtrim(year( @ d )).
您应始终将日期存储为DATETIME
变量,并且仅在显示时使用字符串,如建议的此处 [^ ]
使用以下内容,
SELECT CONVERT ( NVARCHAR ( 12 ),GETDATE(), 101 )
希望这可能对您有用...
In my sql server date format is like this ''dd/mm/yyyy''. But I want to change british format ''mm/dd/yyyy'' . how to change it .
Please help me
解决方案
You don''t. You can''t. The only way to translate a DateTime into a specific format is to convert it to a VARCHAR or other "string" data type. This means that it is no longer a DateTime. It is a VARCHAR.
Here is the code to convert into ''mm/dd/yyyy'' format:
select right('0' + rtrim(month(@d)),2) + '/' + right('0' + rtrim(day(@d)),2) + '/' + rtrim(year(@d)).
You should always store dates as DATETIME
variables, and only use strings when displaying, as suggested here[^].
hi,
use following,
SELECT CONVERT(NVARCHAR(12),GETDATE(),101)
hopes this might be useful for u...
这篇关于在SQL Server中更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文