English 中文(简体)
服务器机质(YYY-MM-DD HH:MI:SS.MMM)
原标题:SQL Server Date Formats (YYYY-MM-DD HH:MI:SS.MMM)

Update: i am still getting this (4/14/2012 2:44:01 PM) result after trying this

 select convert(varchar(30),  4/14/2012 2:44:01 PM ,121) 

End Update

为了取得这一结果,应当采用何种格式:

2012-04-14 14:44:01.683

i 采用这一方法,但并未显示微米/百万分之二

select convert(varchar(23),  4/14/2012 2:44:01 PM ,120)

我得出这一结果:

4/14/2012 2:44:01 PM
最佳回答

http://msdn.microsoft.com/en-us/library/ms187928.aspx” rel=“nofollow”>CAST和CONVERT onDN Books Online, 您无法用一行回答。

SELECT CONVERT(VARCHAR(30), GETDATE(), 121)

这给我带来了以下产出:

2012-04-14 21:44:03.793

<>Update: based on You updated question - 当然,这赢得了t work - Yous reforming a string (The: 4/14/20122:44:01 PM just a string - it sNOT adaytime!”

页: 1

引证:

SELECT CONVERT(VARCHAR(30), CAST( 4/14/2012 2:44:01 PM  AS DATETIME), 121) 

现在你们应当:

2012-04-14 14:44:01.000

显然,由于你最初的数值没有包含任何......,因此这些微秒的数值都是零。

问题回答

更改日期:

select convert(varchar(23), convert(datetime, 4/14/2012 2:44:01 PM ),120)
select convert(varchar(30), CAST( 4/14/2012 2:44:01 PM  As DATETIME),121)




相关问题
Performance impact of indexed view in MS SQL Server 2008

Does anyone have experience with using indexed view in MS SQL Server 2008? I am trying to find out how does indexed view affect performance of insert / update statements, that are adding / updating ...

Lock Escalation - What s happening here?

While altering a table (removing a column) in SQL Server 2008, I clicked the Generate Change Script button and I noticed that the change script it generated drops the column, says "go" and then runs ...

Round to nearest 5 in SQL Server

I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$ select FineAmount from tickets Thanks