note 42265 deleted from function.date by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 10 May 2004 17:31:14 +0000 |
| Subject: | note 42265 deleted from function.date by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69420@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster@internetworks.co.nz
----
This is a script i wrote to convert a date of birth mm/yyyy into the current age this assumes
$DATEOFBIRTH is in format dd/mm/yyyy
<?
$DATEOFBITH = 22/07/1976
// convert into array
$DOB = explode("/", $DATEOFBIRTH);
// simplify for easier coding (optional)
$DOB['dd'] = $DOB[0];
$DOB['mm'] = $DOB[1];
$DOB['yyyy'] = $DOB[2];
// get current month and year
$DATE['y'] = date("Y");
$DATE['m'] = date("m");
// subtract year of birth from current year
$AGE['y'] = $DATE['y']-$DOB['yyyy'];
// subtract month of birth from 12
$AGE['m'] = 12-$DATE['m'];
// next we distinguish wether month of bith is
// future or past, if future, subtract 1 year, as
// my bithday has not occured, therefore i am
// not yet 28
if($AGE['m'] > $DATE['m'])
{
$AGE = $AGE['y']-1;
}
else
{
$AGE = $AGE['y'];
}
echo($AGE); // returns " 27 " as my b-day is yet to come
?>
hope this helps someone, probably a easier way to do this. I'm still learning stuff, so hope
this helps :)