As stated in the PHP.net date() documentation you can check for a specific day number.
So, using that knowledge you can either:
if (date("w", strtotime("+6 months")) == 0) {
echo date("Y-m-d", strtotime("+6 months +1 days"));
}
else {
echo date("Y-m-d", "+6 months");
}
or something in the lines of Bilal Ahmed's answer using a switch
switch (date("w", strtotime("+6 months")) == 0) {
case 0: // Sunday
echo date("Y-m-d", strtotime("+6 months +1 days"));
break;
case 1: // Monday
case 2: // Tuesday
case 3: // Wednesday
case 4: // Thursday
case 5: // Friday
case 6: // Saturday
echo date("Y-m-d", "+6 months");
break;
}
which might be better if there is something to do for every different day as date()
will not be executed every time you perform a case. (Note: I did not compare speeds)
EDIT: oneliner based on the comment of blokish on the askers post
echo date("w", strtotime("+6 months")) == 0 ? date("Y-m-d", "+6 months +1 days") : date("Y-m-d", "+6 months");