Page 1 of 1

Display First three Mondays

Posted: Sun Jul 17, 2011 3:38 am
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:

Re: Display First three Mondays

Posted: Sun Jul 17, 2011 12:22 pm
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

Re: Display First three Mondays

Posted: Sun Jul 17, 2011 12:32 pm
by mwakila
yeah the first three Monday of this months, d= Year-Months-Date. Yeah it should include today if its Monday.

Re: Display First three Mondays

Posted: Sun Jul 17, 2011 5:01 pm
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";
	}
?>