If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back  dBforums > Database Server Software > Oracle > Currend date minus 3 months

LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Registered User
Join Date: Jan 2008
Posts: 8
Currend date minus 3 months

I have a colum which holdes MMYYYY (month and year) I need to query data to extract last 3 months data (MMYYYY between current date and current date minus 3 months)

This ishow I did it in MS SQL
MO_YR BETWEEN CAST(CONVERT(varchar(6),DATEADD(month,-3,GETDATE()),112)as int) AND cast(CONVERT(VARCHAR(6),getdate(),112) as int)

Can some one tell me how to do itin ORACLE
Reply With Quote
  #2 (permalink)  
Registered User
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 7,613
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Don't say, show. Don't promise, prove.
Reply With Quote
  #3 (permalink)  
Registered User
Join Date: Oct 2002
Location: Cape Town, South Africa
Posts: 251
to_date(column, 'mmyyyy') between add_months(sysdate, -3) and sysdate
sysdate = GETDATE()
add_months = DATEADD() but is specific for adding months
Also, would be a good idea to create a function based index on your column that converts it from varchar2 to date. This will speed up your query performance. In general, it's a real bad idea to store date information in varchar2 field.... you often don't get what you expected....
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On