PHP How to find age?

9 points

I have birthdate in php standard format.. How do I find age for the date?

Created by programmer 45 weeks 3 days ago
  Tags:

Answer(s):

-1 points

<php>

 <?php
function age($date_of_birth){
$dob =date('Y-m-d', strtotime($date_of_birth));
$age = date('Y') - date('Y', strtotime($dob));
if (date('md') < date('md', strtotime($dob))) {
$age--;
}
return $age;
}

?>

</php>

 

Therefore, as an example:

See the example below to use the function

 <php>

<?php

$age=age('2-09-1950');

echo $age;
?>
</php>

 

Created by HadaclEaf

Post your Answer

  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Links to specified hosts will have a rel="nofollow" added to them.

More information about formatting options