Skip to next business day if the date falls on a weekend

3

In PHP, I have a certain date, coming from the database, which is the date a request was made.

I need to add 5 business days to this date, which is the deadline for the request to be delivered. At this count I need to ignore the weekends.

I currently have the following code to add 5 days, but the weekend skipping part is being difficult.

Example:

 $data_banco = new DateTime('2016-07-07'); // Quinta

 $data_prazo = clone $data_banco;

 $data_prazo->modify('+5 days'); 

What is the simplest way to add dates, skipping the weekend in PHP?

    
asked by anonymous 27.07.2016 / 17:41

1 answer

6

As I say sometimes, some PHP functions are "talking" (in PHP this is called relative formats ), in this case there is an instruction called weekday , which represents days of the week (or as we call in Portuguese, working days)

If you do this sum any day:

$obj->modify('+5 days');

If you do this will add days of the week which are the "working days":

$obj->modify('+5 weekdays');

Documentation for other instructions / formats (Relative Formats):

27.07.2016 / 17:53