June 21, 2018 at 11:02 am
I need to compare dates
example declare @date date = '6/18/2018'
I need to compare @date should be less than getdate -3
SELECT '6/18/2018'< (Getdate()- 3) --- how do we write this?
June 21, 2018 at 11:08 am
komal145 - Thursday, June 21, 2018 11:02 AMI need to compare dates
example declare @date date = '6/18/2018'I need to compare @date should be less than getdate -3
SELECT '6/18/2018'< (Getdate()- 3) --- how do we write this?
Either in a WHERE clauseSELECT * FROM Table
WHERE '20180618' < (Getdate()- 3)
or a CASE expression.SELECT CASE WHEN '20180618'< (Getdate()- 3) THEN 'True' ELSE 'False' END
FROM Table
Note that you still need to handle time and that I changed your date into an international format.
June 21, 2018 at 2:27 pm
Not sure what you are trying to accomplish here. If you are trying to compare a date on the table to be < (Getdate()- 3) then use Luis's first example, replacing the '20180618' with the column from the table.DECLARE @date DATE = '6/18/2018';
SELECT CASE WHEN @date < (Getdate()- 3)
THEN 'True'
ELSE
'False'
END As GoodDateFlag
FROM Table
;
-------------------------------------------------------------
we travel not to escape life but for life not to escape us
Don't fear failure, fear regret.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply