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?
sql serversql server 2014t-sql
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?
Best Answer
There's no real difference there, but when you start using
DATETIME2
values, or functions that returnDATETIME2
values, you'll get errors.For these, you have to use date math functions.
Aaron Bertrand speaks about this issue briefly in his Bad Habits to Kick series.