如何更新日期时间数据的时间部分? [英] How to update a time part of datetime data..?
本文介绍了如何更新日期时间数据的时间部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的数据库中,我有一个具有这种数据类型的表
In my database i have a table with this type of data
1 Tejas 2011-09-19 15:20:08.200
2 Ankit 2011-09-19 15:21:22.547
3 Jayesh 2011-09-19 15:22:22.300
4 Chirag 2011-09-19 15:28:22.102
5 Sagar 2011-09-19 15:32:15.540
现在,我的问题是,我想更新存储在上述数据中的日期的时间部分,例如if
Now My Question is that i want to update a time part of the date stored in the above data like if
2011-09-19 15:20:08.200
是
2011-09-19 00:00:00.000
表示日期部分将保持不变,但时间将更改.
如果可能的话,我只想对所有查询执行全部操作
means the date part will remain same but the time will be changed.
i want to do it for all with only one query if it is possible
推荐答案
update theTable
set theDate
= dateadd(hh, 8, testDate)
where testDate = dateadd(day, datediff(day, 0, testDate), 0)
或
or
UPDATE yourtable SET yourcolumn=concat(date(yourcolumn), ' 12:00:00') WHERE Id=yourid;
我刚刚在c#中尝试了此操作.根据您的要求,我更改了该行
Hi,
I tried it just now in c#.My line to change that as your requirement is
TextBox1.Text = TextBox1.Text.Substring(0, 10) + " 12:00:00.000 ";
这里的Textbox1表示您的数据库值.
您也可以通过一些更改直接在sql中尝试.
希望这是您的正确答案.
Here Textbox1 means your database value.
You can try it in directly in sql also with some changes.
I hope this your correct answer.
此处提供了一些解决方案: http ://www.bigresource.com/Tracker/Track-ms_sql-KjNEjh0W/ [
some solutions are given here: http://www.bigresource.com/Tracker/Track-ms_sql-KjNEjh0W/[^]
这篇关于如何更新日期时间数据的时间部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文