<?php
function add_deadline($givenDate, $hours){
$range = (ceil($hours/7)*120);
$cnt=1;
$goodhours = array();
foreach(range(1,$range) as $num):
$datetime = date("Y-m-d H:i:s", strtotime('+'.$num.' hour',strtotime($givenDate)));
$time = date("Hi", strtotime('+'.$num.' hour',strtotime($givenDate)));
$day = date("D", strtotime('+'.$num.' hour', strtotime($givenDate)));
if($day != 'Sat' && $day != 'Sun' && $time >= 830 && $time <= 1730):
$goodhours[$cnt] = $datetime;
if($cnt >= $hours && array_key_exists($hours,$goodhours)):
return $goodhours[$hours];
break;
endif;
$cnt++;
endif;
endforeach;
}
//Pass in date and the hours to add on
$future = add_deadline('2014-06-27 08:30:00', '65');
echo $future;
preferences:
64.1 ms | 402 KiB | 5 Q