Jump to content

Query from the last 7 days


Leovenous

Recommended Posts

I would think this is both a common and easy question, but 2 hours of digging have not yielded any results yet, so here goes.

All I want, is a simple query to get data from a table that has been modified in the last 7 days.

I have a field called 'modified' that has a time stamp 0000-00-00 00-00-00. It seems to me I want a way to check the timestamps and grab which ones are less than 7 days old.

So the query might look something like:

[code]SELECT * FROM players WHERE modified  > (SUBDATE(CURDATE(), INTERVAL '7' DAY)[/code]

But obviously I'm bumping around in the dark.

Any help?
Link to comment
Share on other sites

Yep. That worked, and it makes sense. I wonder why I have not been able to find examples of queries even similar. (shrugs)

Thanks a bunch guys. Here's the final query:

[code]$query = "SELECT * FROM players WHERE Creator_ID LIKE '$id' AND modified >= CURDATE( ) - INTERVAL 7 DAY";[/code]
Link to comment
Share on other sites

Personally, I'd use NOW(), not CURDATE(), in case you ever change your modified field to be of type DATETIME, not DATE.  FYI, make sure to always use the field name as the lvalue, so that an index can be used, if available.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.