MYSQL/PHP Query question

I was wondering if anyone on here could help…

I’ve been given the task of creating an index for our website at work based on some data in a database…

Basically, it’s product release date data, the thing is the data is in the following format:

2007-11-01 00:00:00

Some of the release dates are 2020-11-01 00:00:00 but this is too far in the future, what i need to do is have the query return stuff released in the next 30 days.

The table is called P_products and the column with the release dates is called release_date. I know it’s cheeky but would somebody please be able to help me out with an example?


Just like to add, i’m using php for this. I’m guessing i’m going to have to set up a variable with the current date in it so i can use that in the query?

[php]mysql_query(“SELECT * FROM P_products WHERE release_date<= DATE_ADD(CURDATE(),INTERVAL 30 DAY) AND release_date>=CURDATE()”)[/php] … tions.html

there is an example i used to create this query:

Here is an example that uses date functions. The following query selects all rows with a date_col value from within the last 30 days:

mysql> SELECT something FROM tbl_name -> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;

Note that the query also selects rows with dates that lie in the future.

plz have a look at the documenteation next time, most of the times there is allready the answer.

Sponsor our Newsletter | Privacy Policy | Terms of Service