Display First three Mondays

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
mwakila
Forum Newbie
Posts: 2
Joined: Sun Jul 17, 2011 3:31 am

Display First three Mondays

Post by mwakila »

hi,

I want to display the first three Monday which will be form part of a link
example
<a href="http://wwww?d=(my first monday">ETC</a> and so on

Thanks :roll:
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Display First three Mondays

Post by twinedev »

First 3 mondays from what? of this month? the first three mondays after today? (and if today is monday should it include today?)

What format are you expecting the d= value to be?

-Greg
mwakila
Forum Newbie
Posts: 2
Joined: Sun Jul 17, 2011 3:31 am

Re: Display First three Mondays

Post by mwakila »

yeah the first three Monday of this months, d= Year-Months-Date. Yeah it should include today if its Monday.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Display First three Mondays

Post by twinedev »

Code: Select all

<?php
	$intMonth = date('m');
	$intDay = 1;
	$intYear = date('Y');

	$tsFirst = mktime(0,0,0,$intMonth,$intDay,$intYear); // Timestamp for midnight the first of this month

	$intDOW = date('w',$tsFirst); // Get day of week for the first 0=sunday, 1=monday...

	if ($intDOW==0) {  // SUNDAY
		$intDay += 1;
	}
	elseif ($intDOW>1) { // TUES-SAT
		$intDay += 8 - $intDOW;
	}

	// $intDay is now set to the first monday of the month

	for($t=0;$t<21;$t=$t+7) { // 0,7,14 days to add to First Monday
		// Force 2 digit month / day
		echo '<a href="http://wwww?d=',date('Y-m-d',mktime(0,0,0,$intMonth,$intDay+$t,$intYear)),'">ETC</a>',"\n";

		// If you don't care if month/day do not have leading zero if under 10
		echo '<a href="http://wwww?d=',$intYear,'-',$intMonth,'-',($intDay+$t),'">ETC</a>',"\n";

		echo "\n";
	}
?>
Post Reply