开发者

How To Deal with Time only and Date only in Sql server 2008?

According to msdn the general standart for datetime is

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

So if i want to insert into datetime this value i can do it by

update [Readings] set  [StartDate] = '19781222'

But what about time ? how do i add the Time to the YYYYMMDD ?

Question 2 : how d开发者_开发问答o i update only the time in DateTime ?


1st part:

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

2nd:

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

The ultimate guide to the datetime datatypes


Only time: select convert(datetime,'18:22:39',108) //hh:mm:ss

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜