I am writing a Java Program where I am required to select Records for the Current Month from an Oracle database. Any time I need to select Records for the Current day I use:
select * from purchases where purchase_date = to_char(sysdate, 'DD-MON-YYYY')
What Method should I use to select records from the current Month?
On the table the dates appear like:
10/4/2012 //for 4th October 2012
I tried
select * from purchases where purchase_date like to_char(sysdate, 'MON-YYYY')
This selects nothing of course please assist.
If
purchase_dateis a DATE.If
purchase_dateis a VARCHARtrunc(sysdate,’mm’) truncates the current date keeping the month and obviously the year, so
10/04/2012 08:58is truncated to10/01/2012 00:00.