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)
精彩评论