 |
|
|
  |
|
Member
|
|
Join Date: Jan 2004
Location: UK
Posts: 142
|
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Making a calendar
I've created a calendar to add events to but I want to add an option which allows the user to set a recurrence of every third thursday of the month etc. Any ideas on how to do this as at the moment the calendar table just uses the time stamp for the event. I can put an option so that after the event has passed it will change the timestamp but any ideas on how to work out the 3rd Thursday of every month\year etc?
Cheers,
NM.
__________________
Holiday Villa In<br>
<font size=2>If it moves, kick it. If it doesn't move, kick it till it moves and hen kick it because it moved</font>
|
|
|
|
  |
|
Registered User
|
|
Join Date: Apr 2005
Location: Buffalo, NY USA
Posts: 53
|
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try this function
PHP Code:
<?php
// 0 (for Sunday) through 6 (for Saturday)
function dayOfMonth($nMonth, $nYear, $nWeekday, $nInstance) {
// First, we need to know what day of the week the first is on
$nFirstday = date("w", mktime(0, 0, 0, $nMonth, 1, $nYear));
// Next, figure out the date of the first nWeekday we want
$nFirstDate = 1;
while (date("w", mktime(0, 0, 0, $nMonth, $nFirstDate, $nYear)) <> $nWeekday) {
$nFirstDate++;
} // ends while (date("w", mktime(0, 0, 0, $nMonth, $nFirstDate, $nYear)) <> $nWeekday)
// Now, go forward
$nthDate = $nFirstDate+(7*($nInstance-1));
return $nthDate;
} // ends function dayOfMonth($nMonth, $nYear, $nWeekday, $nInstance)
echo("The 3rd Thursday of October, 2006 is " . dayOfMonth(10, 2006, 4, 3) . "\n");
echo("The 1st Friday of October, 2006 is " . dayOfMonth(10, 2006, 5, 1) . "\n");
echo("The 2nd Sunday of December, 2006 is " . dayOfMonth(12, 2006, 0, 2) . "\n");
// Funny date
echo("The 8th Saturday of September, 2006 is " . dayOfMonth(9, 2006, 6, 8) . "\n");
// But if you use that back into date(), it'll work
echo("The 8th Saturday of September, 2006 is " . date("F j, Y", mktime(0, 0, 0, 9, dayOfMonth(9, 2006, 6, 8), 2006)) . "\n");
?>
Example:
Code:
-bash-3.00$ php dayOfMonth.php
The 3rd Thursday of October, 2006 is 19
The 1st Friday of October, 2006 is 6
The 2nd Sunday of December, 2006 is 10
The 8th Saturday of September, 2006 is 51
The 8th Saturday of September, 2006 is October 21, 2006
__________________
Eric
|
|
|
|
  |
|
Member
|
|
Join Date: Jan 2004
Location: UK
Posts: 142
|
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Eric that's just what I'm looking for!
NM.
__________________
Holiday Villa In<br>
<font size=2>If it moves, kick it. If it doesn't move, kick it till it moves and hen kick it because it moved</font>
|
|
 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|