Hi All,
I have 2 dates. I need to check whether Date1 is in previous months or on the same month as Date2.
Say
Case 1:
Date 1 = 30-Jan-2020
Date 2 = 28-Apr-2020
Case 2:
Date 1 = 30-Jan-2020
Date 2 = 28-Apr-2019
I have written below case and It is working for Case 1 but not how to achieve the same for Case 2
SELECT CASE
WHEN TO_NUMBER (
TO_CHAR (TO_DATE ('&&DATE1', 'dd-Mon-YYYY'), 'MM')) <
TO_NUMBER (
TO_CHAR (TO_DATE ('&&DATE2', 'dd-Mon-YYYY'), 'MM'))
THEN
'Y'
ELSE
'N'
END FALLS_ON_PRE_MONTHS
FROM DUAL;
Thanks
Ramesh Selvam