Age Calculator


SUBMITTED BY: PaperBoy

DATE: May 14, 2016, 4:27 p.m.

FORMAT: PHP

SIZE: 427 Bytes

HITS: 507

  1. <?php
  2. function birthday($birthday){
  3. $age = strtotime($birthday);
  4. if($age === false){
  5. return false;
  6. }
  7. list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
  8. $now = strtotime("now");
  9. list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
  10. $age = $y2 - $y1;
  11. if((int)($m2.$d2) < (int)($m1.$d1))
  12. $age -= 1;
  13. return $age;
  14. }
  15. echo birthday('1986-07-22');
  16. ?>

comments powered by Disqus