Jump to content

Finding date a year later


mattyvx

Recommended Posts

Hi!

 

Im creating a CronJob and need a query that will return any members who fall within one week of their 12 month membership.

 

The date they join is recorded as Joined.

 

Something like:

 

"Select Name,Email,Joined From Users WHERE Joined = Joined + 358 DAYS";

 

Thanks in advance

Link to comment
Share on other sites

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add

 

SELECT name, email, joined FROM `users` WHERE joined = DATE_SUB( NOW(), INTERVAL -51 week )

 

For an example. Of course you'll have to figure out the formatting, and you'll probably want to SUBSTR your date field, because this by itself will look for an entry with the exact same time of day. You'll want to search by just the day, I'm sure.

 

It might be easier in the future if when the member is added to the database you included a column with the expiration date. Then you could avoid the SQL-FU.

 

Link to comment
Share on other sites

thanks for your help. I've tried them both and with a bit of changing round ;

 

SELECT name, email, Joined FROM `Users` WHERE Joined = CURDATE()- INTERVAL 358 day

 

That works.

 

abazoskib, your method worked (if i swapped the dates round) but it would return the record every day between that region. I want this as a one off so I can send a reminder a week before subscription ends.

 

Thanks again!

 

 

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.