Guest User

Untitled

a guest
Jan 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. $birthday = '1985-04-15'; //Дата рождения
  2.  
  3. $age = floor( ( time() - strtotime($birthday) ) / (60 * 60 * 24 * 365.25) ); //Формула
  4.  
  5. echo $age; //27
  6.  
  7. function getAge($birthdate, $ageTime = null/*now by default*/){
  8. return (new DateTime())
  9. ->setTimestamp($ageTime ? $ageTime : time())
  10. ->diff(new DateTime($birthdate))->format('%Y');
  11. }
Add Comment
Please, Sign In to add comment