问题
I am trying to store formatted display dates in my tables. For example, I have a date as 20150621 and I want it as June 21, 2015 and 21 juin 2015 (for French).
I have a query: convert(varchar(12),cast([datecolumn]) as datetime),107)
This outputs: Jun 21,2015 , but I need June 21,2015 and also French date.
I am using Sql 2005, so format doesn`t work in it.
回答1:
Write as:
SELECT DATENAME(MM, CAST([datecolumn] AS DATETIME))
+ RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9)
AS [Month DD, YYYY]
from test
Go
SET LANGUAGE French
SELECT CONVERT(VARCHAR(12),CAST(datecolumn AS DATETIME),106) as [DD MON YYYY]
from test
DEMO
回答2:
You can set the Language to French and then run your query. Something like this
SET LANGUAGE us_english
SELECT CONVERT(VARCHAR(12),CAST('2015-01-01' AS DATETIME),107)
SET LANGUAGE French
SELECT CONVERT(VARCHAR(12),CAST('2015-01-01' AS DATETIME),107)
来源:https://stackoverflow.com/questions/29773908/how-to-convert-date-in-english-and-french