On internet you will find so many examples, tutorials for age calculation from date of birth, with complex and confusing programing techniques, but here i had made a very small and easy way to calculate date difference and age using php functions.

If you want to calculate age from given date of birth, use following code.

Calculate Age in Years:

$DateOfBirth      = strtotime(‘2005-11-05’);
$DateDifference   = time() - $DateOfBirth;
$AgeInYears       = $DateDifference /(60*60*24*365);
echo $AgeInYears.' Years';

Calculate Age in Months:

$DateOfBirth      = strtotime(‘2005-11-05’);
$DateDifference   = time() - $DateOfBirth;
$AgeInMonths      = $DateDifference /(60*60*24*30);
echo $AgeInMonths.' months';

Calculate Age in Years and Months:

$DateOfBirth      = strtotime(‘2005-11-05’);
$DateDifference   = time() - $DateOfBirth;
$AgeInMonths      = $DateDifference /(60*60*24*30);
$Years	          = floor($AgeInMonths/12);
$Months           = round($AgeInMonths%12);
echo  $Years.'  years and '.$Months.' months';

Calculate Age in Days:

$DateOfBirth     = strtotime(‘2005-11-05’);
$DateDifference  = time() - $DateOfBirth;
$AgeInDays       = $DateDifference /(60*60*24);
echo $AgeInDays.' days';
BzzBee On December - 9 - 2010

Leave a Reply


Sponsors

  • Add Style to your Life with Home n Women
  • Find Amazing, Unique and Interesting Lists
  • Find Amazing, Unique and Interesting Lists
  • Fashion, Style, Beauty, Home, Entertainment
Apple-Announces-iOS-7-with-Stunning-New-UI-Functional-Layers

Apple Unveils iOS 7

Apple today unveiled iOS 7, the most significant iOS update ...

samsung-galaxy-mega-6.3

Samsung Galaxy Mega

Samsung has proven its mettle in the smartphone arena and ...

venice-italy

VENICE Italy - The M

Country Italy Region Veneto Province Venice (VE) Frazioni Chirignago, Favaro Veneto, Mestre, Marghera, Murano, Burano, Giudecca, Lido, ...

pakistan-india1

2013 ICC Champions T

Birmingham: The result would only be of academic interest but ...

cssbooks

Top 10 Best Books ab

The styles and layouts of your web pages can be ...