Jump to content

Now And 7 Days Ago - How To?


imelendez

Recommended Posts

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

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

  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...