Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Calculate Age

With this function you can calculate the age of a person

Example:
echo "Age is: " . birthday ("1984-07-05");

Result will be (23 Feb 2005) = "Age is: 20"

<?php

  //calculate years of age (input string: YYYY-MM-DD)
  function birthday ($birthday){
    list($year,$month,$day) = explode("-",$birthday);
    $year_diff  = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff   = date("d") - $day;
    if ($day_diff < 0 || $month_diff < 0)
      $year_diff--;
    return $year_diff;
  }

?>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS