Solved

Date result after 3 or 4 working days

Posted on 2004-10-25
182 Views
Last Modified: 2008-02-26
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
    1 Comment
     
    LVL 20

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now