Matt Lyons-Wood
Matt Lyons-Wood

Reputation: 960

Is there any advantage to GETDATE() + x over DATEADD(day,x,GETDATE())?

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:

Is there any advantage or disadvantage to either approach?

Upvotes: 1

Views: 1154

Answers (2)

Suresh
Suresh

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

ForguesR
ForguesR

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

Related Questions