Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Find whether a date falls in previous months when compared to another date

Ramesh SelvamApr 17 2020 — edited Apr 20 2020

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

This post has been answered by Frank Kulash on Apr 20 2020
Jump to Answer
Comments
Post Details
Added on Apr 17 2020
9 comments
1,137 views