我已经看过很多帖子,但似乎无法找到我想要的格式。我正在构建的SQL视图中有多个日期字段。它看起来像这样:2016-02-16 00:00:00.000
我希望它看起来像这样:
02/16/2016 12:00:00 PM
我一直在关注Convert(varchar, datetimefield, 1)
并为其他数字更改1。
有谁知道我需要哪个号码,或者我是否应该使用其他方法来获取我想要的确切格式?
我还希望任何NULL都是空白的,因此在ISNULL(x,'')
中计算如何最好地包装解决方案将是有帮助的,除非解决方案需要以允许isnull的方式工作。
谢谢
谢谢
答案 0 :(得分:0)
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