如何仅在Sql server 2008中处理时间和日期?

时间:2011-08-11 12:45:46

标签: sql-server

根据msdn,datetime的一般标准是

select convert(datetime,'19781222',112)       //YYYYMMDD

因此,如果我想在日期时间插入此值,我可以通过

进行操作
update [Readings] set  [StartDate] = '19781222'

但是时间呢?如何将时间添加到YYYYMMDD?

问题2:我如何仅更新DateTime中的时间?

2 个答案:

答案 0 :(得分:3)

第一部分:

 update [Readings] 
 set  [StartDate] = '19781222 10:23:56'   -- YYYYMMDD 

第二

update [Readings] 
set  [StartDate] = DATEADD(dd, DATEDIFF(dd, 0, [StartDate]), 0) + '12:34:37'

The ultimate guide to the datetime datatypes

答案 1 :(得分:0)

只有时间:     select convert(datetime,'18:22:39',108)// hh:mm:ss