Reputation: 1902
Here is what I am trying to solve.
$nextAppt = "3:45:23";
$keydata = "3:40:10";
I am trying to evaluate weather $nextAppt != $keydata && is not less than 15 minutes to $keydata
.
$keydata
by the way is an array
of times that I am checking $nextAppt
against.
foreach ($taken_time as $keydata ) {
$moredata = strtotime("+15 minutes", strtotime($keydata))
if($nextAppt != $keydata && $taken_time < $moredata ){
}
}
Upvotes: 1
Views: 1175
Reputation: 9458
use http://php.net/manual/en/datetime.diff.php
so
$diff = $time->diff($time2);
if ($diff->h == 0 && $diff->m < 15) {
...
}
Upvotes: 1
Reputation: 1470
It's much easier to convert the times while calculating the unix time stamps. Then it's a matter of just subtracting:
$nextAppt - 900 (15 minutes * 60 seconds)
Upvotes: 0
Reputation: 632
Use PHP Datetime object.
$keydata = new DateTime("3:40:10");
$nextAppt = new DateTime("3:45:23");
$diff = $keydata->getTimestamp() - $nextAppt->getTimestamp();
if (abs($diff) > 60*15)
{
// TODO
}
Upvotes: 0