Code: Select all
counting how many years, months and days go since any date past to current date, eg. 15-05-2007 (historical date) - 26-04-2010 (current date) = 2 years, 11 months, 19 days.
I've tried something like this:
[syntax=php]
<?php
$d1 = strtotime('2007-05-15');
$d2 = time();
$y1 = date('Y', $d1);
$y2 = date('Y', $d2);
$m1 = date('n', $d1);
$m2 = date('n', $d2);
$da1 = date('d', $d1);
$da2 = date('d', $d2);
$year_diff = $y2 - $y1;
$month_diff = $m2 - $m1;
$days_diff = $d2 - $d1;
echo $year_diff. " years, " .$month_diff. " months, " .$days_diff. " days";
?>
[/syntax]
but this script doesn't working exactly what i need: it deduct years, months and days separatly - 2010-2007=3 years, 04-05= -1 months, 26-15= 93120711 days.
Please, help me to solve this problem.
Best regards,
Jack