简体   繁体   中英

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM