JAy PaTel
JAy PaTel

Reputation: 75

What is the difference between StartDate > DateAdd(dd,-1,@EndDate) and StartDate >=@EndDate?

What is the difference between this

StartDate > DateAdd(dd,-1,@EndDate)

and this

StartDate >=@EndDate

Upvotes: 0

Views: 182

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269613

They are the same if StartDate and EndDate have a date data type.

If they a time component then the logic is different.

Consider:

EndDate    2017-05-09 11:00:00

Then the first gets everything after 2017-05-08 11:00:00.

The second gets everything on or after 2017-05-09 11:00:00. Clearly, these are different.

I should also add: When using date parts, spell out the full name of the date part. So use this:

StartDate > DateAdd(day, -1, @EndDate)

rather than using dd. This makes the code easier to read. It also prevent problems with abbreviations. Is mm for minutes or months? Is ms for milliseconds or microseconds? Why bother trying to remember?

Upvotes: 2

Related Questions