I recently came across this:
SELECT
'Y',
ltrim(rtrim(upper(Newly_Eligible)))
FROM Table
WHERE
Id = 1
AND
(Convert(datetime, Convert(varchar, GETDATE(),103),103)
BETWEEN
Convert(datetime,Convert(varchar, [Start_Date],103),103)
AND
Convert(datetime, Convert(varchar, [End_Date] ,103),103))
Start_Date
, End_Date
and obviously GETDATE()
are all datetime
types. Why does he cast to a varchar and then back again?
This truncates any excess time-of-day value out of the datetime leaving just the date value. (The key is the conversion code "103".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With