Jump to content
Sign in to follow this  
imelendez

Now And 7 Days Ago - How To?

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

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

The logic should be similar, although you should look up the function reference for that database to see what's available.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...