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_date
is a DATE.
select *
from
purchases
where
purchase_date >= trunc(sysdate,'mm')
If purchase_date
is a VARCHAR
select *
from
purchases
where
to_date(purchase_date,'mm/dd/yyyy') >= trunc(sysdate,'mm')
trunc(sysdate,'mm') truncates the current date keeping the month and obviously the year, so 10/04/2012 08:58
is truncated to 10/01/2012 00:00
.
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