Please help ... php minutes counter

Hi, anyone,

I have this code:


<?php

$date1 = "2007-03-24";
$date2 = date('Y-m-d');

$diff = abs(strtotime($date2) - strtotime($date1));

$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

printf("%d years, %d months, %d days\
", $years, $months, $days);

?>

But i want to add hours, minutes and secundes.

Can you help me ? I simply cant do it. :blush:

http://www.phpclasses.org/package/1965-PHP-Calculate-and-spell-the-timespan-between-two-dates.html
You need an account

Oh, great. Just for 2 code lines I need an account.

That’s great ! Thank you. :frowning:

You don’t need 3rd party code to do that, PHP has built-in classes that can handle the job:


$date1 = new DateTime("2007-03-24");
$date2 = new DateTime();

$diff = $date2->diff($date1);

printf("%d years, %d months, %d days, %d hours, %d minutes, %d seconds\
", $diff->y, $diff->m, $diff->d, $diff->h, $diff->i, $diff->s);

Thank you very much, fretburner !
The code work like a charm and I am very happy to see that.
Thank you again ! :slight_smile: