Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Date result after 3 or 4 working days

Posted on 2004-10-25
Medium Priority
196 Views
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
0
Question by:WvR
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
1 Comment

LVL 20

Accepted Solution

virmaior earned 750 total points
ID: 12400128
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
###### Suggested Courses
Course of the Month9 days, 16 hours left to enroll