How many saturdays have passed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

How many saturdays have passed

Post 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!
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: How many saturdays have passed

Post 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;
}
Post Reply