如何将军事时间转换为MM / dd / yyyy hh:mm:s tt in SQL Server

时间:2015-03-13 01:38:20

标签: sql-server

我有一个来自临时表DateCreated的列,其输出为2/23/2015 17:28,但我想将其转换为2/23/2015 5:28 PM

我目前的代码如下:

SELECT t1.DateCreated 
FROM #tempTable t1

2 个答案:

答案 0 :(得分:2)

1

中使用100convert function样式
select convert(varchar(30),DateCreated ,1)+' '+
       RIGHT(CONVERT(VARCHAR,DateCreated , 100), 7) AS time

DEMO

答案 1 :(得分:2)

请使用此查询:

SELECT CONVERT(VARCHAR(35),t1.DateCreated,109) FROM #tempTable t1

Referance:http://www.w3schools.com/sql/func_convert.asp