最佳解答者
Changing Date format on SQL Server Management Studio /SQL Server

問題
-
Hi
I am wondering if there any way I can chnage the Date format from US TO UK
E.g. On the query if you want to select a record which the date field has value of 26th March 2008.
If US format
We need to do
SELECT *
FROM TableName
WHERE DateField='03/26/2008'
On the other hand if you enter the DateField in UK Format
you will receive an Error
[The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.]
I would be grateful if you could let me know it is some setting on the SQL server to read the text value as US date format of UK date format. Or the changes I need to make is on SQL Management Studio or On my Computer ...etc
Many thanks
Chi
解答
-
Hello Chi,
Please try the following method.
SET DATEFORMAT DMY
GO
http://technet.microsoft.com/en-us/library/ms189491.aspx
[SET DATEFORMAT (Transact-SQL)]
Hope this helps.
Best regards,
Wen Yuan
所有回覆
-
Hello Chi,
Please try the following method.
SET DATEFORMAT DMY
GO
http://technet.microsoft.com/en-us/library/ms189491.aspx
[SET DATEFORMAT (Transact-SQL)]
Hope this helps.
Best regards,
Wen Yuan
-
Hi Wen Yuan
Thanks very much for your information.
Thanks
Chi
--------------------------------
Sorry Wen Yuan
The problem has not been fixed, When I used MS SQL Management Studio Create/ Alter the Stored procedure/Function, it does not keep that
SET DATEFORMAT dmy
GO
in that stored procedure.
After I updated the function, and I click on Modify function again the command above disappeared.
I am wondering it that command would work on Function.
Do you have any suggest about any changes I need to make to make it work?
Many thanks
Chi