imelendez Posted February 19, 2016 Share Posted February 19, 2016 Hello Community - I am trying to figure out the sql query to provide me the results that I am looking for in date range from now to 7 days prior. Use Case: When running sales reports for our company, I would like for the query to look at the database and basically pull the last 7 days data. How is this done and could you direct me in that direction, please? Thank you in advance. -Isaiah Link to comment Share on other sites More sharing options...
justsomeguy Posted February 19, 2016 Share Posted February 19, 2016 It depends how you store the dates. If you store them as integer timestamps then you can just use basic math to figure out when 7 days ago was. You can also use BETWEEN: http://www.techonthenet.com/mysql/between.php Assuming you're using MySQL, look through the date and time functions. You can use things like date_sub to subtract from today's date, for example. http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html 1 Link to comment Share on other sites More sharing options...
imelendez Posted February 23, 2016 Author Share Posted February 23, 2016 Hello, Thanks for the information. However, I did fail to provide a little more information. I was trying to figure out how to do this on MSSQL. Will the logic be the same or is there a reference link that I need to look at that will work best with MSSQL? Thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted February 23, 2016 Share Posted February 23, 2016 The logic should be similar, although you should look up the function reference for that database to see what's available. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now