Execute a cron task only on certain days with PHP

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.";

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Hide Your Site From Search Engines by using PHP 404 Header Code

You are reading this article because you want a surefire way to prevent your PHP pages from being...

Force download a file with PHP

This is a super helpful script if you need to force download a PHP file from another location on...