Jump to content

Recommended Posts

Hi all,

 

I am trying to figure out how to calculate 5 working days prior to a given date.

 

I have done some googling but can only see examples of how to add 5 working days onto a date, such as this:

 

$holidayList = array();
$j = $i = 1;

while($i <= 5)

{
    $day = strftime("%A",strtotime("+$j day"));
    $tmp = strftime("%d-%m-%Y",strtotime("+$j day"));
    if($day != "Sunday" and $day != "Saturday" and !in_array($tmp, $holidayList))
    {
        $i = $i + 1;
        $j = $j + 1;
    }
    else
        $j = $j + 1;
}
    $j = $j -1;
echo strftime("%A, %d-%m-%Y",strtotime("+$j day"));

 

Does anyone know how to calculate 5 working days prior to a date?

 

Many thanks,

 

Greens85

Hi,

 

Many thanks for your response.

 

I didn't try that but now I have it works perfectly..

 

I just need to figure out which part holds todays date now as I don't want to subtract from that but rather I date I have stored in a database.

 

I assume this is perfectly doable with the provided code?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.