[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL query to return records from the past X number of days

Posted on 2011-05-06
9
Medium Priority
?
327 Views
Last Modified: 2012-06-27
can somebody  please tell me how to write this query using ADDDATE function
0
Comment
Question by:Nura111
  • 4
  • 3
  • 2
9 Comments
 
LVL 9

Accepted Solution

by:
Philippe Damerval earned 1000 total points
ID: 35710326
Using your expression from the other question (which you didn't quote in this one):

select * from myTable where OrderDate >= ADD_DATE(CURDATE(), INTERVAL 30 DAY)

hth


Philippe
0
 

Author Comment

by:Nura111
ID: 35710334
Thank you! sorry i closed the question and i thought this will be more understood thats way!
0
 
LVL 24

Assisted Solution

by:johanntagle
johanntagle earned 1000 total points
ID: 35710337
Nura111, in your previous question you were already given the link to the reference page of mysql time and date functions: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html.  It's best to learn by actually trying it out.  There are many functions you can use: DATE_ADD, ADDDATE (synonym for DATE_ADD), DATE_SUB, SUBDATE (synonym for DATE_SUB)

To use ADDDATE:

select * from myTable where OrderDate >= ADDDATE(curdate, interval -30 day)
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:Nura111
ID: 35710347
I know, sorry I was in a middle of learning milion other things thought i could use some help on this one
0
 
LVL 9

Expert Comment

by:Philippe Damerval
ID: 35710350
.. assign points?
0
 

Author Comment

by:Nura111
ID: 35710356
and its curdate()
0
 

Author Comment

by:Nura111
ID: 35710359
what do you mean .. assign points?
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 35710373
Yeah sorry, my malady due to mixing ruby (which makes the () optional when calling functions) and SQL.

Assign points - damerval wants his EE points for helping you out
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 35710382
Which you already gave =)  Thanks.  How I wish EE is like google mail which gives you a notification if there are new posts on the same thread.  
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question