How long has it been

I have 2 dates in any format (let's say in Timestamp) I need to find out how much time has passed from one time to another. Of course, I can just subtract one date from another, and get the time in seconds. But I need to find out how much time has passed in DAYS, MONTHS, and YEARS, taking into account leap years and that different months have a different number of days.

That is, if the event occurred on October 1 of this year (the second date should be today), then zero days have passed, one a month and zero years. If the event occurred on October 15, then 17 days, zero months, and zero years have passed.

All this needs to be implemented using PHP or Java Script. Thank you in advance =)

4 answers

Well for example:

$day = floor( ($next - $past) / 86400 );
print "Между данными датами прошло <b>". $day ."</b> дней";
 2
Author: thunder, 2012-11-01 14:25:50

In short, guys, thanks for a bunch of links. @thunder your link helped me a lot. But, anyway, I will write the answer myself

<?php
   $time = '2012-06-12 16:56';
   $datetime1 = date_create($time);
   $datetime2 = date_create('now',new DateTimeZone('Europe/Moscow'));
   $interval = date_diff($datetime1, $datetime2);
   $interval->format('%y years %M months %D days');
?>

If something is wrong, comment

 2
Author: Виталий Заславский, 2012-11-01 21:21:46
$t1=time();
// что-то делаем, делаем, делаем, делаем
$t2=time();
$times=$t2-$t1;

echo "Time running script ".$times. "seconds";

Well, in this spirit, well, and then convert it to a normal view

Well, here there is a ready-made solution

 1
Author: Artem, 2012-11-01 13:22:12
echo date_diff(new DateTime(), new DateTime('2015-10-09 00:00:01'))->days;
 0
Author: FORTRAN, 2015-05-10 16:19:44