Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $date = date('Y-m-01'); $next_month = date('Y-m-d', strtotime('+1 month', strtotime($date))); function nextWorkDay($date) { $day_of_week = date('N', strtotime($date)); if ($day_of_week>5) { echo "Weekend:" . $date . PHP_EOL; if ($day_of_week == 7) { echo "Weekend:" . date('Y-m-d', strtotime('+1 day', strtotime($date))) . PHP_EOL; } $shift = 8-$day_of_week; return date('Y-m-d', strtotime("+{$shift} day", strtotime($date))); } else { echo "Work day:" . $date . PHP_EOL; echo "No work day:" . date('Y-m-d', strtotime('+1 day', strtotime($date))) . PHP_EOL; echo "No work day:" . date('Y-m-d', strtotime('+2 day', strtotime($date))) . PHP_EOL; return date('Y-m-d', strtotime('+3 day', strtotime($date))); } } while ($date < $next_month) { $date = nextWorkDay($date); }
Copy Clear