How to check whether some date is in the current calendar month or not in oracle DB

  • A+
Category:Languages

I need to print records which have the current calendar month as the enrolled month.

I used sysdate for this function. But, I'm not sure if that is correct or not.

My code would be,

select * from student where sysdate,trunc('mm') = enrolled_month; 

I just need some way to print current month using sysdate function.

Any kind of help will be appreciated.

Thanks in advance.

 


Here is another option using TO_CHAR:

SELECT * FROM student WHERE TO_CHAR(sysdate, 'Month') = enrolled_month; 

But I don't think it's a good idea to store the enrollment month name (and perhaps the other components) separate from the enrollment date. Just store the date once, and then use Oracle's date functions to work that data.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: