在SQL Server中仅更新日期中的时间

在SQL Server中仅更新日期中的时间

问题描述:

大家好,

我的问题是我需要在ASP.NET应用程序中更新时间,但要保留相同的日期.例如,在SQL Server中将"11/22/2005 4:00:00 PM"更改为"11/22/2005 5:30:00 PM".我在将值传递到更新语句中的表时遇到问题.

请让我知道如何实现.
谢谢你
Mohd.wasif

Hi All,

My problem is that I need to update the time, but keep the same date, in my ASP.NET application. For example, change "11/22/2005 4:00:00 PM" to "11/22/2005 5:30:00 PM" in sql server. I''m having problems passing the values to the table in an update statement.

Please let me know how to accomplish it.
Thanking You
Mohd.wasif

我相信您需要DATEADD函数:

http://msdn.microsoft.com/en-us/library/ms186819%28v = SQL.90%29.aspx [ ^ ]
I believe you need the DATEADD function:

http://msdn.microsoft.com/en-us/library/ms186819%28v=SQL.90%29.aspx[^]


您的ASP.Net应用程序应将完整日期发送到数据库,即2005年11月22日5:30 :00 PM.然后,您可以使用普通的Update语句并更改数据.
Your ASP.Net application should send the complete date to the daatabase i.e. 11/22/2005 5:30:00 PM. Then you can use a normal Update statement and change the data.


尝试此

从asp.net以字符串形式传递它
然后
这样使用

更新Test5设置doj = dateadd(dd,datediff(dd,0,doj),''11:59:00.000'')其中id = 1
try this

Pass it in string from asp.net
and then
use it like that

update Test5 set doj =dateadd(dd,datediff(dd,0,doj),''11:59:00.000'') where id= 1