Page 1 of 1

How many saturdays have passed

Posted: Wed Jan 11, 2012 9:22 pm
by xionhack
Hello! I want to be able to make a code that tells me how many saturdays have passed till today in this month. I've tried a couple of things but nothing. Any help?! Thanks!

Re: How many saturdays have passed

Posted: Thu Jan 12, 2012 12:02 am
by twinedev
Going from the first of the current year, and counting the current week if today is Saturday:

Code: Select all

function numberSaturdays() {
	$dowStart = date('w',mktime(0,0,0,1,1,date('Y')));
	$dowNow = date('N');
	$numSaturdays = date('W');
	if (date('m')==1 && $numSaturdays > 50) { $numSaturdays = 0; }
	if($dowStart < 5 && $dowNow < 6) { $numSaturdays--; }
	elseif($dowStart > 4 && $dowNow > 5) { $numSaturdays++; }
	return $numSaturdays;
}