sql server convert date to string MM/DD/YYYY

匿名 (未验证) 提交于 2019-12-03 02:18:01

问题:

I am using SQL Server 2008.

I have the following:

    select convert(varchar(20),fmdate) from Sery 

How do I convert the date to string such that it show as MM/DD/YYYY

回答1:

That task should be done by the next layer up in your software stack. SQL is a data repository, not a presentation system

You can do it with

CONVERT(VARCHAR(10), fmdate(), 101) 

But you shouldn't



回答2:

select convert(varchar(10), fmdate, 101) from sery 

101 is a style argument.

Rest of 'em can be found here.

T-SQL Cast / Convert date to string



回答3:

select convert(varchar(10), cast(fmdate as date), 101) from sery 

Without cast I was not getting fmdate converted, so fmdate was a string.



回答4:

 Find All Date Formats for SQL. 

http://%20http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!