SQL 如何将分钟添加到日期时间的时间部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33760529/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:11:39  来源:igfitidea点击:

How to add minutes to the time part of datetime

sqlsql-serverdatetimetimedateadd

提问by Anyname Donotcare

How to add minutes(INT)to the time part of datetime?

如何添加minutes(INT)到时间部分datetime

For example :

例如 :

If i have datetime variable like this :

如果我有这样的日期时间变量:

  @shift_start_time =  2015-11-01 08:00:00.000

  @increase = 30


How to get the result :

如何得到结果:

2015-11-01 08:30:00.000

回答by Lukasz Szozda

Use DATEADD:

使用DATEADD

SELECT DATEADD(mi, @increase,   @shift_start_time);

db<>fiddle demo

db<>小提琴演示

回答by Simone

Using dateadd:

使用日期添加:

DATEADD(minute,@increase,@shift_start_time)

the first argument can be chosen among: year quarter month dayofyear day week weekday hour minute second millisecond microsecond nanosecond

第一个参数可以从以下选项中选择: year 季度 Month dayofyear day week weekday hours minute second 毫秒 微秒 纳秒

please check https://msdn.microsoft.com/it-it/library/ms186819%28v=sql.120%29.aspx

请检查https://msdn.microsoft.com/it-it/library/ms186819%28v=sql.120%29.aspx

回答by Aditya Prabhu

To add minutes to the time part of datetime =>

将分钟添加到 datetime 的时间部分 =>

SELECT DATEADD("mi", @increase,   @shift_start_time);