Reputation: 960
As I understand it, there are 2 main ways to add/subtract days to a date/datetime in MS SQL Server:
For example, to add one day, there is:
GETDATE() + 1
DATEADD(day, 1, GETDATE())
Is there any advantage or disadvantage to either approach?
Upvotes: 1
Views: 1154
Reputation: 1169
In my opinion GetDate()+1
will add just 1 day to current date, there is no way to add months or years in current date, but if you want to add month, year, hours etc o than DATEADD
provide various options using that you can get past\future dates based on current date.
So if you are trying to add just day, than both would have same impact.
Thanks Suresh
Upvotes: 1
Reputation: 3618
No real advantages except that when you use GETDATE()+1 we don't really know what you are adding (days, months, hours, seconds?).
DATEADD makes it explicit and also ease your job when you need to add something else than days.
Upvotes: 4