Execute a cron task only on certain days with PHP Print

  • 2

The code below can be used to execute code during certain days of the week.

So, once a day, you would send a cron to wherever this code is located and it will only execute on Mondays - Fridays.

//we only want to send this on monday-Friday.
$day_name = date('D');

//execute this script weekdays only
if($day_name == "Sat" || $day_name == "Sun") {

 echo "error - this script can only run mondays to friday. Today is $day_name.";
 exit;

}

Was this answer helpful?

« Back