An age calculation function written in php precise to the day
- /**
- * PHP age calculation function
- *
- * Parameters support parameter passing by array and standard Mysql date
- * Params sample
- *-----------------
- $ BirthArr = array (
- 'Year' => '123 ',
- 'Month' => '11 ',
- 'Day' => '3'
- );
- $ BirthStr = '2017-2000 ';
- *------------------
- *);
- * @ Author
- * @ Copyright (c) 2011,2012 Just Use It!
- * @ Link IT tumbler http://yungbo.com http://bbs.it-home.org
- * @ Param string | array $ birthday
- * @ Return number $ age
- */
- Function getAge ($ birthday ){
- $ Age = 0;
- $ Year = $ month = $ day = 0;
- If (is_array ($ birthday )){
- Extract ($ birthday );
- } Else {
- If (strpos ($ birthday ,'-')! = False ){
- List ($ year, $ month, $ day) = explode ('-', $ birthday );
- $ Day = substr ($ day, 0, 2); // get the first two chars in case of '2017-11-03 12:12:00'
- }
- }
- $ Age = date ('Y')-$ year;
- If (date ('M') <$ month | (date ('M') ==$ month & date ('D') <$ day )) $ age --;
- Return $ age;
- }
- ?>
|