SQL Server:向日期时间字段添加秒数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3480784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server: Add seconds to a datetime field?
提问by Unknown Coder
This should be a softball for you SQL guys. I know I can add to an int field with something like UPDATE tblUser SET Total=(Total+2)
but what is the syntax for adding seconds to a datetime field?
这应该是你们 SQL 家伙的垒球。我知道我可以使用类似的东西添加到 int 字段,UPDATE tblUser SET Total=(Total+2)
但是将秒添加到日期时间字段的语法是什么?
I'm using SQLServer 2008
我正在使用 SQLServer 2008
回答by Matthew Jones
UPDATE tbluser SET DateField = DATEADD(ss,numOfSeconds,DateField)
Note the first parameter "ss". This shows that you are adding seconds to the date.
注意第一个参数“ss”。这表明您正在为日期添加秒数。
Check the docsfor more info.
查看文档以获取更多信息。