-4

Possible Duplicate:
How to calculate the difference between two dates using PHP?

Can someone show me code for calculating a birthday into a year month day hours minutes and seconds

Example : Aug 8, 1993

The expected result would be like this :

As of Dec 16, 2012 11:04 Your age is 19 years 4 months 12 days 11 hours 4 minutes and 23 seconds

Community
  • 1
  • 1
chachi
  • 13
  • 5

1 Answers1

1

try this

    <?php 
       $birthday = new DateTime("2007-03-24");
       $today = new DateTime();
       $interval = $birthday->diff($today);
       echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";     
    ?>

How to calculate the difference between two dates using PHP?

Community
  • 1
  • 1
Kasun
  • 679
  • 1
  • 7
  • 21
  • 4
    @Kasum: Please don't copy answers, especially as this question is a duplicate. Leave a link as a comment below the question itself to the answer instead. – hakre Dec 16 '12 at 08:09
  • i have added link also and modified to match @cathe's requirement – Kasun Dec 16 '12 at 08:10
  • @hakre I read on meta that you like to close questions, but what is wrong with copying the relevant parts? I personally hate it to follow dozens of redirects. – rekire Dec 16 '12 at 08:13
  • @rekire: That is why it is important to not duplicate content too much. That not only keeps redirects low, it also allows to locate the information more quickly on the site. Closing is very helpful in that case, duplicating content not. – hakre Dec 16 '12 at 08:18