SQL查询格式日期时间?

我看过很多帖子,但似乎无法找到我期待的格式。 我正在构建的SQL视图中有多个dateime字段。 它看起来像这样: 2016-02-16 00:00:00.000

我希望它看起来像这样:

02/16/2016 12:00:00 PM

我一直在寻找Convert(varchar, datetimefield, 1)并将其他数字改为1。

有谁知道我需要哪个数字,或者如果我应该使用不同的方法来获得我想要的确切格式?

我也希望任何NULL都是空白的,因此,如果ISNULL(x,'')方法需要以允许isnull的方式工作,那么计算如何最好地将解决方案包装在ISNULL(x,'')将会很有帮助。

谢谢

谢谢


select  convert(varchar(20),getdate(),101) 
+ ' ' +
right(convert(varchar(32),getdate(),108),8) AS Date_Time -- this gives you military time but you can replace it with this which gives you AM/PM
right(convert(varchar(20), getdate(), 100) ,8) --AM/PM
链接地址: http://www.djcxy.com/p/62543.html

上一篇: SQL Query Format Datetime?

下一篇: Where I can find .fon format specification?