note 42265 added to function.date
| From: | webmaster at internetworks dot co dot nz | Date: | Mon, 10 May 2004 13:38:18 +0000 |
| Subject: | note 42265 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69408@lists.php.net to get a copy of this message | ||
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 :)
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42265
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42265&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42265&report=yes
Search -- http://master.php.net/manage/user-notes.php