Jump to content

Query From the Database where date is older than 2 weeks


madjack87

Recommended Posts

In the database I am storing the date with CURDATE

 

What I need to do is query the database to show any records that are more than 14 days older then todays date.

 

$result = mysql_query("SELECT * FROM customers WHERE stage = 0, TO_DAYS(CURDATE()) - TO_DAYS(date)>14 ORDER BY date");

 

I know the above code is not correct I just wanted to show everyone what I have been trying.

 

Can I use DATE SUB?

 

Any help would be appreciated.

 

thanks

Link to comment
Share on other sites

I tested that query locally, and the syntax is correct. I assume you edited it to match your table structure, right? Echo the query string, along with mysql_error(), and post those please.

 

$query = "SELECT `field` FROM `table` WHERE `date` < DATE_SUB( CURDATE(), INTERVAL 14 DAY )";
if( !result = mysql_query($query) ) {
     echo "<br>Query : $query<br>Failed with error: " . mysql_error() . '<br>';
}

 

EDIT: I see where I originally left a closing `backtick` off of the table name. Did you catch that and add it?

Link to comment
Share on other sites

Here is my Error

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' < DATE_SUB( CURDATE(), INTERVAL 14 DAY ) ORDER BY date' at line 1

 

here is my code

$result = mysql_query("SELECT * FROM customers WHERE date' < DATE_SUB( CURDATE(), INTERVAL 14 DAY ) ORDER BY date") or die ('Error: '.mysql_error ());

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.