• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7640
  • Last Modified:

Today's date filter- Oracle (My SQL)

I have a column which has date/time.  I want to the query to only show records in the past year from the date run (using something similar to getdate in MS SQL).  I am using MY SQL, but I think it will be similar to (if not the same as Oracle).  Thanks.
0
jjrr007
Asked:
jjrr007
  • 2
  • 2
1 Solution
 
sleepyorionCommented:
Use this

SELECT YOUR_COLUMN_NAME FROM YOUR_TABLE
WHERE YOUR_COLUMN_NAME >  SYSDATE - 365

*Replace 365 with any amount of date you wish*
0
 
Cornelia YoderArtistCommented:
SELECT * FROM Table WHERE ADDDATE(Datefield, INTERVAL 1 YEAR) > NOW()
0
 
jjrr007Author Commented:
My SQL took the Now() funtion.  

Unfortunately, It returned a syntax error with the using the sysdate.  

I can use the now() function but I need to be able to say go one year back.  Unforunately, the -365 and the adddate function didn't work.  Kindly advise
0
 
jjrr007Author Commented:
yodercm,

Your solution worked.  I just had to use -1 and change the > to <.  Thanks a lot.
0
 
Cornelia YoderArtistCommented:
You're welcome.  You might check out the SUBDATE which is exactly like ADDDATE but you won't need the minus sign :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now