Jump to content

mysql search


ted_chou12

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

[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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.