nez-bol nez-bol - 13 days ago 4
PHP Question

How to get $date + 5 to exclude weekends?

I have some pages that require a date to be set in the future (either 2 or 5 days as set by a variable).
This date needs to be only counting Monday - Friday, excluding weekends.

What I have so far ($tts is the variable of 2 or 5 depending on page);

$Today = date('N:m:y');
$NewDate = date('l \t\h\e jS \o\f F',strtotime($Today) + (24*3600*$tts));
$businessDays = [1, 2, 3, 4, 5];
echo $NewDate;


This works without excluding weekend days.
I have tried to use the $businessDays but I'm unsure of how I can use this to count what days are between $Today and $NewDate

Answer

Try:

$plusFive = strtotime( '+5 weekday' );
$plusFive = date( 'Y-m-d', $plusFive );

strtotime also takes a second parameter which could be the base for the +5.