Home » SQL & PL/SQL » SQL & PL/SQL » compare date (month & year)
compare date (month & year) [message #264783] Tue, 04 September 2007 10:23 Go to next message
Messages: 1
Registered: September 2007
Junior Member

How do I compare between two date with just month and year. below is my SQL, have error:
What I want is to achieve is:
assume now is Sep 2007, I want those student records where their registration date is between these 4 months (sep, oct, nov and dec).

Below is my statement:
select registration_date 
from student_table 
where  to_date(registration_date ,'mm/yyyy') < to_date(trunc(add_months(sysdate, 3)),'mm/yyyy')

pls advise....


[Updated on: Tue, 04 September 2007 10:28] by Moderator

Report message to a moderator

Re: compare date (month & year) [message #264787 is a reply to message #264783] Tue, 04 September 2007 10:33 Go to previous messageGo to next message
Michel Cadot
Messages: 65144
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Does registration_date a date or a string?
TO_DATE function only applies on strings and return a date.

If registration_date is a date and following your requirement, the condition is more:
registration_date between trunc(sysdate,'month')
                      and add_months(last_day(sysdate),3)

Re: compare date (month & year) [message #264874 is a reply to message #264783] Tue, 04 September 2007 21:23 Go to previous message
Messages: 143
Registered: May 2002
Senior Member
thank you so.....much.....I manage to get what I want.


Previous Topic: Purchased Items summary
Next Topic: output of date format (merged)
Goto Forum:

Current Time: Sat Aug 19 17:25:17 CDT 2017

Total time taken to generate the page: 0.06817 seconds