1
DECLARE @MinutesToAdd int = 20; DECLARE @StartTimeDate datetime = '2017-06-05 14:37:56.113'; DATEADD(minute,@MinutesToAdd,@StartTimeDate); 

Code above adds 20 minutes to StartTimeDate. Is there a good way to remove those 20 minutes not add? Tried to find a solution, but didn't catch one. Any ideas?

3
  • Please add the DBMS tag Commented Jun 16, 2017 at 7:00
  • 1
    try passing -20 Commented Jun 16, 2017 at 7:01
  • Added sql server tag based on the syntax used Commented Jun 16, 2017 at 7:04

2 Answers 2

4

You don't have any specific function to subtract any dateparts

Just add negative symbol in front

Select DATEADD(minute,-@MinutesToAdd,@StartTimeDate); 

or multiply with -1

Select DATEADD(minute,@MinutesToAdd * -1 ,@StartTimeDate); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

 DECLARE @MinutesToAdd int = -20; DECLARE @StartTimeDate datetime = '2017-06-05 14:37:56.113'; select DATEADD(minute,@MinutesToAdd,@StartTimeDate); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.