Re: All Monday's & Thursdays
- From: "Janwillem Borleffs" <jw@xxxxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 02:01:10 +0200
Stuart Colman wrote:
I need to display every Monday and Thursday, and their relevant dates
for a given month.
I have looked at a few things, but not really got past being able to
show one Monday or Thursday.
Any ideas or pointers?
function getMonThuForMonth($month, $year = 0) {
// Day array
$dates = array();
// set the year
if (!$year) $year = date('Y');
// verify the month
if ($month < 1 || $month > 12) return false;
// first: get initial timestamp
$ts = mktime(0, 0, 0, $month, 1, $year);
// get all timestamps related to the Mondays
// and Thursdays of the month
while ($month == date('m', $ts)) {
if ('Mon' == date('D', $ts)) {
$dates[] = $ts;
}
$day = date('D', $ts = strtotime('thursday', $ts));
if ($month == date('m', $ts)) {
$dates[] = $ts;
}
$ts = strtotime('next monday', $ts);
}
return $dates;
}
$dates = getMonThuForMonth(6);
foreach ($dates as $date) {
echo date('Y M D (d)', $date), '<br />';
}
JW
.
- Follow-Ups:
- Re: All Monday's & Thursdays
- From: Janwillem Borleffs
- Re: All Monday's & Thursdays
- References:
- All Monday's & Thursdays
- From: Stuart Colman
- All Monday's & Thursdays
- Prev by Date: looping through text with array_key_exists function
- Next by Date: Re: All Monday's & Thursdays
- Previous by thread: All Monday's & Thursdays
- Next by thread: Re: All Monday's & Thursdays
- Index(es):