How to add minutes to the time part of datetime

梦想的初衷 提交于 2019-12-22 03:48:16

问题


How to add minutes(INT) to the time part of 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

回答1:


Use DATEADD:

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

db<>fiddle demo




回答2:


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

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




回答3:


To add minutes to the time part of datetime =>

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


来源:https://stackoverflow.com/questions/33760529/how-to-add-minutes-to-the-time-part-of-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!