开发者

format date to 105 in SQL Server after casting

I have a problem: I have a datetime and I need the date to specific format

So I just casted datetime to time

SELECT CAST (GETDATE() AS DATE) -- result (2011-06-08)

and for formatting I use convert

SELECT CONVERT(DATE, CAST (GETDATE() AS DATE), 105) --result (2011-06-08)

105 format (dd-mm-yy)

but, the result of bot开发者_JS百科h is same,

CONVERT is not working for 105 formatting,

Any ideas?

thanks


To get the results you're looking for you need to convert the DATE to a VARCHAR like this:

SELECT CONVERT(VARCHAR(10),CAST (GETDATE() AS DATE),105)

If you cast to a DATE, you will always get the full DATE.

You can truncate the date by re-casting to the DATE type.

SELECT CAST(CONVERT(VARCHAR(10),CAST (GETDATE() AS DATE),105) as DATE)


You can use as

SELECT Convert(varchar, getdate(), 105)


select convert(varchar(50),date,105) as Date
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜