Jump to content

[SOLVED] Date Search


ainoy31

Recommended Posts

Hello-

 

I am designing a mailing list and trying to do a manual search for birthdays and anniversaries.  I am needing to search for any birthdays within 2 weeks from the current time.    Here is my query:

 

$sql = "SELECT * FROM ml_users WHERE user_bday BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 14 DAY)";

 

Any suggestion is helpful.  ty

Link to comment
Share on other sites

OK. I found a work around the year.  I changed my birthday and anniversart data type to varchar with the input format of "mmdd".  I am now able to query successfully. 

 

$sql = "SELECT * FROM ml_users WHERE user_bday = date_format(now(),'%m%d')";

 

The only problem now is that this searches the current day but what if I want to search up to 2 weeks from current date.  Any suggestion is appreciated.

 

Link to comment
Share on other sites

OK. I found a work around the year.  I changed my birthday and anniversart data type to varchar with the input format of "mmdd".  I am now able to query successfully. 

 

$sql = "SELECT * FROM ml_users WHERE user_bday = date_format(now(),'%m%d')";

 

The only problem now is that this searches the current day but what if I want to search up to 2 weeks from current date.  Any suggestion is appreciated.

 

 

Wow, that's a terrible solution.  Leave it as a day, convert it the current year, and then use between...

Link to comment
Share on other sites

maybe the way you called my idea TERRIBLE.  i do appreciate help and tips from this forum but one should be more careful on their wordings... thank you

 

There are plenty of terrible ideas on this forum, and I'll continue to point them out... like storing "lists" in the single field, trying to change the auto_increment value, etc.    Besides, terrible doesn't always mean bad per se... just extremely distressing.  And more than that, I haven't seen any attempt to implement the plethora of solutions provided in the link I gave you.

Link to comment
Share on other sites

Cool.  The issue is solved.  Thanks man.  I was checking out different things.  Followed your suggestion and it is working.  Here is my solution:

 

$sql = "SELECT * FROM ml_users WHERE (DAYOFYEAR(curdate()) <= dayofyear(user_bday) AND DAYOFYEAR(curdate()) + 30 >= dayofyear(user_bday) OR DAYOFYEAR(curdate()) <= dayofyear(user_bday) + 365 AND DAYOFYEAR(curdate()) + 30 >= dayofyear(user_bday) + 365)";

 

TY.  AM

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.