SQL Query Format Datetime?
I've seen a lot of posts on this, but can't seem to find the format I am looking for. I have multiple dateime fields in a SQL view I am building. It looks like this: 2016-02-16 00:00:00.000
I want it to look like this:
02/16/2016 12:00:00 PM
I've been looking at Convert(varchar, datetimefield, 1)
and changing out the 1 for other numbers.
Does anyone know which number I need, or if I should use a different method to get the exact format I want?
I also want any NULLs to be blank, so it will be helpful to figure how to best wrapper the solution in an ISNULL(x,'')
unless the solution needs to be worked in a way that will allow an isnull.
Thank you
Thank you
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/62544.html
上一篇: 资产txt文件的Android路径
下一篇: SQL查询格式日期时间?