Calculate age (jQuery or PHP) based on date of birth [not based on user input]

后端 未结 4 798
青春惊慌失措
青春惊慌失措 2021-01-16 04:27

I am looking for a JavaScript or PHP script that allows me to calculate somebody\'s age based on his/her date of birth in the mm/dd/yyyy format. I found this ve

4条回答
  •  旧时难觅i
    2021-01-16 05:07

    PHP:

    $today = new DateTime();
    $birthdate = new DateTime("1973-04-18 09:48:00");
    $interval = $today->diff($birthdate);
    echo $interval->format('%y years');
    

    See it in action. You can obviously format the out to suit your needs.

提交回复
热议问题