Anyname Donotcare
Anyname Donotcare

Reputation: 11393

How to add minutes to the time part of datetime

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

Upvotes: 47

Views: 155011

Answers (3)

Simone
Simone

Reputation: 1924

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

Upvotes: 22

Lukasz Szozda
Lukasz Szozda

Reputation: 175706

Use DATEADD:

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

db<>fiddle demo

Upvotes: 84

Aditya Prabhu
Aditya Prabhu

Reputation: 57

To add minutes to the time part of datetime =>

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

Upvotes: 3

Related Questions