PHP Last Business Day / Week Day


Here’s how to get the last ended business day / week day in php

function last_business_day()
{
	if(	date("w") >= 1 && date("w") <= 5)
	{
		if(	date("H") >= 16)
		{
			return date("Y-m-d");
		}else{
			return date("Y-m-d",strtotime("yesterday"));
		}

	}else{
		return date("Y-m-d",strtotime("last friday"));
	}
}

Of course if you wanted to include the current business day you could useĀ 8 o-clock instead of 16


function last_business_day()
{
	if(	date("w") >= 1 && date("w") <= 5)
	{
		if(	date("H") >= 8)
		{
			return date("Y-m-d");
		}else{
			return date("Y-m-d",strtotime("yesterday"));
		}

	}else{
		return date("Y-m-d",strtotime("last friday"));
	}
}

Leave a comment

Your email address will not be published. Required fields are marked *