Jump to content

Recommended Posts

I stored users' dob all in one single column, but when I want to perform a search, the more ideal situation would be searching their age range instead of date of birth. I do know how to do a search with "%" sign which you could do if you stored the data as age, so range such as 10~19 would be something like "1%" but when storing data as birthdates, the situation is harder, can anyone suggest me how could i do it.
btw, this is the function to calculate age through dob:
[code]
function birthday($birthday)
{list($year,$month,$day) = explode("-",$birthday);
$year_diff  = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff  = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
return $year_diff;}
[/code]
Thanks
Ted
Link to comment
https://forums.phpfreaks.com/topic/33572-mysql-search/
Share on other sites

actually, I remembered, you can use the max() and min() for mysql search, so what I only need to do is to convert the age into dob, and plug in the two to give a range, would this work? if yes, can anyone tell me how you can convert age to dob?
Thanks
Link to comment
https://forums.phpfreaks.com/topic/33572-mysql-search/#findComment-157204
Share on other sites

[quote author=genericnumber1 link=topic=121759.msg501186#msg501186 date=1168423589]
you know you can query a range of dates... something like

SELECT * FROM Users WHERE dob BETWEEN '1/1/2006' AND '1/1/2007'
[/quote]

Can you use BETWEEN in MySQL?  I didn't realise you could?  I know it's available in Oracle

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/33572-mysql-search/#findComment-157209
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.