Date result after 3 or 4 working days

Hello,

I have a request form and i want te get a speciale date.
In my database there is a table "closed"

In the table "closed" i entered some days when we are closed.

In my request form i want:
If the server time is < 10.00 AM the result should be today + 2 working days (not the weekend and not the closed days, if there is a closed day then the next working day).
If the server time is > 10.00 AM the result should be today + 3 working days (not the weekend and not the closed days, if there is a closed day then the next working day).

When there is a request in a weekend it should be monday + 2 working days (not the weekend and not the closed days, if there is a closed day then the next working day).

Could some one help setting this up???

Thank you,
HP van Hagen
WvR
LVL 1
WvRAsked:
Who is Participating?
 
virmaiorConnect With a Mentor Commented:
here these two functions have all of the logic you'll need..

function fixDate(&$mydate,$am = 7, $pm = 18)
{
if (date("H",$mydate) < $am) { $mydate = $mydate + ($am * 60*60) - (date("H",$mydate)*3600)-(date("i",$mydate)*60); }
if (((date("H",$mydate) * 60) + date('i',$mydate) ) > $pm * 60 )
   { $mydate = $mydate - (((date("H",$mydate) * 60) + date('i',$mydate) )*60) + (24*60*60) + ($am * 60*60); }
if (date("w",$mydate) == 0 ) $mydate = $mydate + 24*60*60 + ($am * 60*60) - (date("H",$mydate)*3600)-(date("i",$mydate)*60);
if (date("w",$mydate) == 6 ) $mydate = $mydate + (24*60*60)*2;
}

function workTimeDiff($start,$end,$am = 7,$pm = 18)
//This function finds the working difference between two dates (only uses work days; doesn't correct for holidays
{
//these next two lines let the function handle both timestamps and string times..
if ($start + 1  < 10000) {$start = strtotime($start);}
if ($end + 1  < 10000) {$end = strtotime($end);}
//if for some reason you make the beginning of the day after the end then it reverses..
if ($pm < $am) {
   $xm = $pm;
   $pm = $am;
   $am = $xm;
}

$dir = 1;
fixDate($start,$am,$pm);
fixDate($end,$am,$pm);
//these next two lines bump the dates into work time periods


if ($start > $end) {
   $dir = -1;
   $tx = $end;
   $end = $start;
   $start = $tx;
}


$diff = 0;
$daydiff = ((date("Y",$end) - date("Y",$start))*52*5) +  ((date("W",$end) - date("W",$start))*5) + (date("w",$end) - date("w",$start));
$secdiff = ((date("H",$end) - date("H",$start))*60*60) +  ((date("i",$end) - date("i",$start))*60) + (date("s",$end) - date("s",$start));


if ($secdiff < 0) {$daydiff = $daydiff - 1;
                                 $secdiff = $secdiff + (60*60)*($pm-$am);
                              }

//This would pring the results
printf("\n<br>");
printf($daydiff . " Days " . $secdiff . " Seconds");
printf("\n<br>");
printf($daydiff . " Days " . ($secdiff / 3600) . " Hours");
}
0
All Courses

From novice to tech pro — start learning today.