I want to write a query that tells me when is a person's particular birthday this year. for leap years just go with the next month. I was planning to achieve this by calculating the difference between today and their date of birth and adding it to their date of birth. If a person is born in first of November of 1999 I want to calculate when is their birthday for this year. The expected output is first of November of this year. This are my attempts to achieve this:
I tried by counting how many months between the two dates and adding it to the date of birth.
select ADD_MONTHS(to_date('01-NOV-1999'), ROUND(MONTHS_BETWEEN(TRUNC(SYSDATE), to_date('01-NOV-1999')))) from dual;
This output the following:
01-OCT-19
I tried calculating how many days in between the birth date and today and adding that to their date of birth. However, this doesn't seem to work correctly:
select to_date('01-NOV-1999') + (TRUNC(SYSDATE) - to_date('01-NOV-1999')) from dual;
OUTPUT: 02-OCT-19
What I hope to get is 01-Nov-2019 (the system date I posted this is 02-OCT-19) both seem to be a month behind my expected output. If I try to run the same query with OCT instead of NOV in the first query, it works correctly.
I am using Oracle Database 11g