How to get this: 2011-02-09 13:09:00
怎么得到这个:2011-02-09 13:09:00
I want this format in sql:
我想在sql中使用这种格式:
MM DD YYYY HH:MM:SS
07/22/2014 01:51:57 AM/PM
2 个解决方案
#1
1
You may try like this:
你可以尝试这样:
QUERY
SELECT CONVERT(VARCHAR(10), GETDATE(), 104) + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108)
or try this:
或试试这个:
DECLARE @dt DATETIME = Getdate();
DECLARE @time VARCHAR(32) = CONVERT(VARCHAR, @dt, 109);
SELECT CONVERT(CHAR(10), @dt, 101) + ' '+RIGHT('0'+
Substring(@time, Len(@time) -
Charindex(' ', Reverse(@time)) +2,
Charindex(' ', Reverse(@time)) -
Charindex(':', Reverse(@time))-1),8)
+ ' '+RIGHT(@time, 2);
#2
0
You can run this sql, if you are querying the data:
如果要查询数据,可以运行此sql:
alter session set nls_date_format='DD-MON-RR HH:MI:SS'
#1
1
You may try like this:
你可以尝试这样:
QUERY
SELECT CONVERT(VARCHAR(10), GETDATE(), 104) + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108)
or try this:
或试试这个:
DECLARE @dt DATETIME = Getdate();
DECLARE @time VARCHAR(32) = CONVERT(VARCHAR, @dt, 109);
SELECT CONVERT(CHAR(10), @dt, 101) + ' '+RIGHT('0'+
Substring(@time, Len(@time) -
Charindex(' ', Reverse(@time)) +2,
Charindex(' ', Reverse(@time)) -
Charindex(':', Reverse(@time))-1),8)
+ ' '+RIGHT(@time, 2);
#2
0
You can run this sql, if you are querying the data:
如果要查询数据,可以运行此sql:
alter session set nls_date_format='DD-MON-RR HH:MI:SS'