note 113800 added to function.date
| From: | espertalhao04 at hotmail dot com | Date: | Wed, 04 Dec 2013 10:19:48 +0000 |
| Subject: | note 113800 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197736@lists.php.net to get a copy of this message | ||
Simple function to calculate a person's age.
You simply provide the day, month and year and it gives the age.
Since it is simple, it won't count for negative numbers.
<?php
function age($d=1,$m=1,$y=1970)
{
$n=explode(' ',date('d m Y'));
if($n[2]<$y)return 0;
return $n[2]-$y-1+(($n[1]=$m&&$n[0]>=$d)||($n[1]>$m));
}
?>
For today (04-12-2013), if you run:
<?php
age(4,12,1992);
?>
You will get 21.
If you run:
<?php
age(5,12,1992);
?>
You will get 20.
This function uses the date() function. Results will vary according to your timezone.
----
Server IP: 194.8.30.16
Probable Submitter: 77.54.215.164
----
Manual Page -- http://php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/113800
Del: integrated -- https://master.php.net/note/delete/113800/integrated
Del: useless -- https://master.php.net/note/delete/113800/useless
Del: bad code -- https://master.php.net/note/delete/113800/bad+code
Del: spam -- https://master.php.net/note/delete/113800/spam
Del: non-english -- https://master.php.net/note/delete/113800/non-english
Del: in docs -- https://master.php.net/note/delete/113800/in+docs
Del: other reasons-- https://master.php.net/note/delete/113800
Reject -- https://master.php.net/note/reject/113800
Search -- https://master.php.net/manage/user-notes.php