I was wondering what the difference between the following two methods is:

     GETUTCDATE()-2  
and

      DATEADD(d,-2,GETUTCDATE())

I guess using `DATEADD` is the correct way, but was wondering why?
Top Answer
meme (imported from SE)
There's no real difference there, but when you start using `DATETIME2` values, or functions that return `DATETIME2` values, you'll get errors.

    SELECT SYSDATETIME() - 1 AS [Incompatible]

> Msg 206, Level 16, State 2, Line 17 Operand type clash: datetime2 is
> incompatible with int

For these, you have to use date math functions. 

    SELECT DATEADD(DAY, -1, SYSDATETIME()) AS [Compatible]

Aaron Bertrand speaks about this issue briefly in his [Bad Habits to Kick][1] series. 


  [1]: https://sqlblog.org/2011/09/20/bad-habits-to-kick-using-shorthand-with-date-time-operations

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.