Reputation: 5931
I'm trying to get the total minutes and seconds that have elapsed from the following step by step:
1: strtotime('now') - strtotime('-1 day');
2: Ill get something back like 120 lets say...
3: So... 120 = 2 minutes -- My problem is the remainder though!
4: Examples:
130 = 2 minutes 10 seconds
130 / 60 = 2.1666~
121 = 2 minutes 1 seconds
121 / 60 = 2.0166~
122 = 2 minutes 2 seconds
122 / 60 = 2.0366~
explode
on the period,
and use the remainder, but that's not right.PS: I never had a gift for Math.
Upvotes: 0
Views: 643
Reputation: 32158
This is how you can use PHP's DateTime
::diff
which returns DateInterval
$dt = new DateTime();
$dt2 = new DateTime("-120 seconds");
$diff = $dt->diff( $dt2 );
echo( $diff->format("%i min and %s sec") );
Upvotes: 1
Reputation: 173562
You can also use DateTime math (php >= 5.3):
$d1 = new DateTime(strtotime('now'));
$d2 = new DateTime(strtotime('-1 days'));
$diff = $d1->diff($d2);
echo "{$diff->i} minutes, {$diff->s} seconds\n";
Upvotes: 1