开发者

Change format of datetime in SQL

开发者 https://www.devze.com 2023-02-25 05:01 出处:网络
I want format like 17-April-2011 9:05 PM How to do开发者_高级运维 this in sql queryUse the CONVERT or CAST function (see documentation) which offer a number of formats. But be careful with what yo

I want format like

17-April-2011 9:05 PM

How to do开发者_高级运维 this in sql query


Use the CONVERT or CAST function (see documentation) which offer a number of formats. But be careful with what you do with it. This is fine for displaying, but could result in inefficient queries if you use the result in a query expression.

And if you are using it for display, you will probably have better formatting options in the language you are using at the UI level.


Try CONVERT(varchar(50), datecol, 130) - format 130 seems closest and replace some spaces?


The closest you can get from the built-in CONVERT function is 17 Apr 2011 9:05:00:000PM:

SELECT convert(varchar, getdate(), 130)

See also:

  • How to format datetime & date in Sql Server 2005 by Anubhav Goyal
  • CAST and CONVERT (Transact-SQL) on MSDN


113 is also similar:

SELECT convert(varchar, getdate(), 113)
0

精彩评论

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