I have the following code. I need to spread values out evenly between two times: now + 20 minutes to 15:30. The following code is a part of a loop that I did not include for the sake of brevity.
$numlines = count($data);
$calltime = date('U', strtotime('+20 minutes');
$to = date('U', strtotime('15:30'));
$from = $calltime;
$diffinsec = $to - $from;
$apptseparation = ceil($diffinsec / $numlines);
$calltime = date('H:i', strtotime('+' . $apptseparation . ' seconds', $calltime);
What I'm trying to do here is take the current time plus 20 minutes, convert it to a Unix epoch, and subtract it from 15:30 on the same day. The result should be the number of seconds between the two times.
I want to then divide the number of seconds by the total number of lines in my input file, giving me the total number of seconds between each value. Finally, I want to add this number to the existing $calltime variable so each iteration of the loop will add the new time.
What I have doesn't work, though. Date math always confuses me, and in PHP doubly so. If you need any more information, please let me know!
Well, what are the result you get and the result you expect for? This code seems to work if I well understood:
$calltime = strtotime('+20 minutes');
$from = $calltime;
$to = strtotime('15:30');
$diffinsec = $to - $from;
if ( $diffinsec < 0 ) { // If it is 18:04 per example
$diffinsec *= -1;
}
$apptseparation = ceil($diffinsec / $numlines);
$calltime = date('H:i', strtotime('+'.$apptseparation.' seconds', $calltime));