Jump to content

Calculate 5 working days prior to a give date


greens85

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.