Jump to content

Expire within 30 days


craigeves

Recommended Posts

Hi again

 

Can someone please help?

 

I want to show all promotions that are set to expire within 30 days. This is what I have:

SELECT promotions.promo_id, promotions.ret_id, promotions.title, promotions.`desc`, promotions.terms, promotions.publish, promotions.expiry
FROM promotions
WHERE promotions.expiry <= DATE_ADD( day ,30 , GETDATE() ) 

 

but it returns the following 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 '30 , GETDATE() )' at line 1

 

Can someone help?

 

Thanks in advance

Link to comment
Share on other sites

OK - I got it working using:

 

SELECT promotions.promo_id, promotions.ret_id, promotions.title, promotions.desc, promotions.terms, promotions.publish, promotions.expiry
FROM promotions
WHERE promotions.expiry <= DATE_ADD( now(), INTERVAL 1 MONTH) 

 

but for some reasons it returns results that are already expired also. can anyone tell me why???

 

Thanks

 

Craig

 

Link to comment
Share on other sites

I don't know if this will help you at all, as it appears you are looking really for an SQL solution, not a php solution.  Which, if that is the case, you may wish to post in that section of the forum instead.

 

Here is a piece of code I used on a website to put New Members (30 days old or less) into a different listing:

 

/* Set a date back 30 days ago */
$date = date("m/d/Y");
$newdate = strtotime ( '-30 day' , strtotime ( $date ) ) ;
$newdate = date ( 'm/d/Y' , $newdate );
echo $newdate;
/* $newdate is now 30 days in the past, new accounts cannot be more than 30 days old */

 

Then you could do something like WHERE promotions.expiry > $newdate

Link to comment
Share on other sites

You are asking for dates that are less-than or equal to the result of the date_add(), which will be all the dates that are less-than or equal to one month from the current date/time -

WHERE promotions.expiry <= DATE_ADD( now(), INTERVAL 1 MONTH) 

 

What exactly do you want to match, relative to the current date?

 

Also, NOW() is a date/time value. What type of values are in expiry? If you want to compare just the date parts, use CURDATE() instead of NOW().

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.