473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

I need a genius for this one!

What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.

How do I do this. My brain hurts enough already from writing the
function above. Can anyone help?

Sep 18 '06 #1
6 1258
In message <11**********************@h48g2000cwc.googlegroups .com>,
ameshkin <am**********@gmail.comwrites
>What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.

How do I do this. My brain hurts enough already from writing the
function above. Can anyone help?
Do it in the SQL you use to select from the database. Of course this
assumes you have used a date-type column to hold the date of birth!

For MySQL see:
http://dev.mysql.com/doc/refman/5.0/...functions.html

Check the YEAR function.

--
Surfer!
Email to: ramwater at uk2 dot net
Sep 18 '06 #2
ameshkin wrote:
What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.

How do I do this. My brain hurts enough already from writing the
function above. Can anyone help?
Hi ameshkin.

Here is the approx solution to ur answer. You can do things by Query.
Here is the query for that You needs to just modify little by PHP and
Pass it on to the My-SQL u will get poper age.

SELECT name, birth, CURRENT_DATE,
-(YEAR(CURRENT_DATE)-YEAR(birth))
-- (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
-AS age
-FROM pet;
/***** There is nothing impossible coz Impossible itself means I M
Possible. :)
Regards,
Mitul Patel

Sep 18 '06 #3
ameshkin wrote:
What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.
I assume from the above that you are storing birthdays in the database
as strings. This is more trouble than it's worth. Most databases have
a date type, and functions which allow easy comparisons, etc.

MySQL, for instance, has loads:
http://dev.mysql.com/doc/refman/5.1/...functions.html
--
Oli

Sep 18 '06 #4
Yes, thats one problem. For other reasons, teh date is in the database
as a string. When I get home, i will changbe the structure around and
see if i can just use a simple sql query to get my results.

Thanks for the help
Oli Filth wrote:
ameshkin wrote:
What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.

I assume from the above that you are storing birthdays in the database
as strings. This is more trouble than it's worth. Most databases have
a date type, and functions which allow easy comparisons, etc.

MySQL, for instance, has loads:
http://dev.mysql.com/doc/refman/5.1/...functions.html
--
Oli
Sep 18 '06 #5
ameshkin wrote:
What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.

How do I do this. My brain hurts enough already from writing the
function above. Can anyone help?
Friend!, if you have to cross post make sure you have all of the
newsgroups in to TO: statement before you send it. It stops you from
wasting other peoples time not knowing someone else had resolved your
problem already in another group!

First off, you should keep the date in the database the default format
'yyyy-MM-DD'.

I am not handling leap years but gives you a start. You may want to
build a procedure to do all of this and include leap year:

$minAge = 24;
$maxAge = 54;

SELECT
LASTNAME,
FIRSTNAME,
ROUND(DATEDIFF(CURDATE(),birthday)/365) AS 'numberOfYears',
birthday
FROM table
WHERE
ROUND(DATEDIFF(CURDATE(),birthday)/365) <= $maxAge AND
ROUND(DATEDIFF(CURDATE(),birthday)/365) >= $minAge;

--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Sep 18 '06 #6
ameshkin wrote:
What I am trying to do, is...

Find users in a database between two ages.

$minage
$maxage

The birthdays of the users are in the database in this format
01-30-1980

Now this function takes a birthday in this format 1980-01-30 and
returns the age

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;
}

But what I need to do, is somehow only show the results from the
database where the birthday is in between two different ages.

How do I do this. My brain hurts enough already from writing the
function above. Can anyone help?
Friend!, if you have to cross post make sure you have all of the
newsgroups in to TO: statement before you send it. It stops you from
wasting other peoples time not knowing someone else had resolved your
problem already in another group!

First off, you should keep the date in the database the default format
'yyyy-MM-DD' as a DATE Type..

I am not handling leap years but gives you a start. You may want to
build a procedure to do all of this and include leap year:

$minAge = 24;
$maxAge = 54;

SELECT
LASTNAME,
FIRSTNAME,
ROUND(DATEDIFF(CURDATE(),birthday)/365) AS 'numberOfYears',
birthday
FROM table
WHERE
ROUND(DATEDIFF(CURDATE(),birthday)/365) <= $maxAge AND
ROUND(DATEDIFF(CURDATE(),birthday)/365) >= $minAge;


--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Sep 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Westcoast Sheri | last post by:
Normally, if I want to know if someone viewed a particular page, I use the php's "mail()" function (because I check my email lots more than I check my weblogs :-) Now I want to know how get php...
34
by: George Hester | last post by:
<html><head><script>z='yCj45%20zeB0+e%21%29OpA6%2CNTn*mkK0+euxe%23i%24NTn*%2 92%2C%29/%21J6%20%7E%3A%20ScUglJ5%2C%5B3G%3DewU%26q%24Ut%3BDA%3CR@FKyp%3Exv%...
236
by: Andrew Rawnsley | last post by:
Anyone out there using beta 2 in production situations? Comments on stability? I am rolling out a project in the next 4 weeks, and really don't want to go though an upgrade soon after its released...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: Daniel Dupont | last post by:
Hi there, I want to test a String. This string must be made of - 8 numbers - then a single underscore - and then 6 numbers Can anybody tell me what can be the right .Net pattern ? String...
2
by: Roy | last post by:
I am very, very new to ASP.NEt and have never done ASP. I have been trying to get a datagrid to work for about 5 days with very limited results. When I use property builder, bind the control, set...
6
by: GHUM | last post by:
I need to split a text at every ; (Semikolon), but not at semikolons which are "escaped" within a pair of $$ or $_$ signs. My guess was that something along this should happen withing csv.py;...
3
by: yoyojava | last post by:
here go to this link: http://staff.beaumont.k12.tx.us/jchauvi/CS2/CS2.html ..... then click on PROJECT:Bruin Grocery ... and i am done with everything except for step 5 and 6 the search methods.. i...
3
by: DivinDave | last post by:
Any help with this would be greatly appreciated. I need to create a query and my SQL skills are very very rusty. Lets say I have the following; Database name = users Table name = info1 Table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.