Get age in years


/ Published in: PHP
Save to your folder(s)

This function will get the age in years. It compares the inserted date with the current date and outputs the result.


Copy this code and paste it in your HTML
  1. function get_age($birthday)
  2. {
  3. $birth = strtotime($birthday);
  4. $now = strtotime('now');
  5.  
  6. $age = ($now - $birth) / 31536000;
  7.  
  8. echo floor($age);
  9. }
  10.  
  11. get_age('15 march 1984');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.