41

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 this result?

2015-11-01 08:30:00.000
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

3 Answers3

71

Use DATEADD:

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

db<>fiddle demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
18

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://learn.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?redirectedfrom=MSDN&view=sql-server-ver16

kashlo
  • 2,313
  • 1
  • 28
  • 39
Simone
  • 1,828
  • 1
  • 13
  • 20
1

To add minutes to the time part of datetime =>

SELECT DATEADD("mi", @increase,   @shift_start_time);
G_real
  • 1,137
  • 1
  • 18
  • 28
Aditya Prabhu
  • 37
  • 1
  • 5