HTML CSS JavaScript jQuery AJAX ASP PHP SQL tutorials, examples for web building ,author kapil kumar: Age calculation in php

Sunday 30 November 2014

Age calculation in php

Age calculation in php



Declare a function =>

  1. function getAge( $dob, $date )
  2. {
  3.     $dob=strtotime($dob);
  4.     $date=strtotime($date);
  5.         $age = 0;
  6.         while( $date > $dob = strtotime('+1 year', $dob))
  7.         {
  8.                 ++$age;
  9.         }
  10.         return $age." years";
  11. }

Assign values to variables=>

  1. $dob= "01-07-1991";
  2. $today_date=date("d-m-Y");

Call the function =>

     echo "Total age ". getAge($dob,$today_date);

No comments:

Post a Comment