I have saved a date in my oracle db. (Pattern: dd.MM.yyyy) Now I have to check/compare by day and month, if today ss the same date or exactly 6 months after. But the year has to be ignored. For example. My date is 01.02.2001. Then it has to be "true" at the 01.02.2002.
Also I need to check if the date + 6 months is true. (halfyearly). (For example 01.02.2002 --> 01.08.2002)
I tried with sysdate, but I'm a noob in sql.
You can do the comparison using to_char()
:
where to_char(yourdate, 'MM-DD') = to_char(sysdate, 'MM-DD')
For six months:
where to_char(yourdate, 'MM-DD') = to_char(add_months(sysdate, 6), 'MM-DD')
You can also use
substr(date1,5) =substr(date2,5)
this code compares first five characters of the data and checks if they are identical or not.
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