Currently I’m comparing short dates this way:
CONVERT(datetime,CONVERT(VARCHAR(10), return_date,101)) = '{0}'
My supervisor says that I should do it this way:
datepart(month,return_date)= 5
and datepart(day,return_date)=24
and datepart(year,return_date)=2011
because the defined value 101 recognized by the function CONVERT might change in the future. Is that true? How often do these parameter values change? Have the changed in the past? Is there an even better way to compare the short form of dates?
If by “short dates” you mean “just the date without the time”
First, note the
<in the second part of the Where clause. Second, if there is an index onreturn_date, this approach will use it. Another solution which would not utilize an index (and thus result in a table scan) would be:If
return_dateis always stored without its time component (i.e., its time component is always midnight) then you can do a simple comparison: