I have some code that I want to make sure is if not the fastest but a good way to do it. Basically it displays weeks from this current weeks monday to sunday out to 6 weeks. Then from there 4 months out by the month. Tell me what you think.
$year = date('Y');
$today_date = date('Y-m-d');
$week_1 = date('Y-m-d', strtotime("last monday"));
//Weekly Events
if ( $week_1 != $today_date ) {
//This Week (Week 1)
$week_1_start = date('Y-m-d', strtotime("last monday"));
$week_1_end = date('Y-m-d', strtotime("last monday +6 days"));
$week_1_start_long = date('M j', strtotime("last monday"));
$week_1_end_long = date('M j', strtotime("last monday +6 days"));
//Next Week (Week 2)
$week_2_start = date('Y-m-d', strtotime("last monday +7 days"));
$week_2_end = date('Y-m-d', strtotime("last monday +13 days"));
$week_2_start_long = date('M j', strtotime("last monday +7 days"));
$week_2_end_long = date('M j', strtotime("last monday +13 days"));
//Week 3
$week_3_start = date('Y-m-d', strtotime("last monday +14 days"));
$week_3_end = date('Y-m-d', strtotime("last monday +20 days"));
$week_3_start_long = date('M j', strtotime("last monday +14 days"));
$week_3_end_long = date('M j', strtotime("last monday +20 days"));
//Week 4
$week_4_start = date('Y-m-d', strtotime("last monday +21 days"));
$week_4_end = date('Y-m-d', strtotime("last monday +27 days"));
$week_4_start_long = date('M j', strtotime("last monday +21 days"));
$week_4_end_long = date('M j', strtotime("last monday +27 days"));
//Week 5
$week_5_start = date('Y-m-d', strtotime("last monday +28 days"));
$week_5_end = date('Y-m-d', strtotime("last monday +34 days"));
$week_5_start_long = date('M j', strtotime("last monday +28 days"));
$week_5_end_long = date('M j', strtotime("last monday +34 days"));
//Week 6
$week_6_start = date('Y-m-d', strtotime("last monday +35 days"));
$week_6_end = date('Y-m-d', strtotime("last monday +41 days"));
$week_6_start_long = date('M j', strtotime("last monday +35 days"));
$week_6_end_long = date('M j', strtotime("last monday +41 days"));
} else {
//This Week (Week 1)
$week_1_start = date('Y-m-d', strtotime("now"));
$week_1_end = date('Y-m-d', strtotime("now +6 days"));
$week_1_start_long = date('M j', strtotime("now"));
$week_1_end_long = date('M j', strtotime("now +6 days"));
//Next Week (Week 2)
$week_2_start = date('Y-m-d', strtotime("now +7 days"));
$week_2_end = date('Y-m-d', strtotime("now +13 days"));
$week_2_start_long = date('M j', strtotime("now +7 days"));
$week_2_end_long = date('M j', strtotime("now +13 days"));
//Week 3
$week_3_start = date('Y-m-d', strtotime("now +14 days"));
$week_3_end = date('Y-m-d', strtotime("now +20 days"));
$week_3_start_long = date('M j', strtotime("now +14 days"));
$week_3_end_long = date('M j', strtotime("now +20 days"));
//Week 4
$week_4_start = date('Y-m-d', strtotime("now +21 days"));
$week_4_end = date('Y-m-d', strtotime("now +27 days"));
$week_4_start_long = date('M j', strtotime("now +21 days"));
$week_4_end_long = date('M j', strtotime("now +27 days"));
//Week 5
$week_5_start = date('Y-m-d', strtotime("now +28 days"));
$week_5_end = date('Y-m-d', strtotime("now +34 days"));
$week_5_start_long = date('M j', strtotime("now +28 days"));
$week_5_end_long = date('M j', strtotime("now +34 days"));
//Week 6
$week_6_start = date('Y-m-d', strtotime("now +35 days"));
$week_6_end = date('Y-m-d', strtotime("now +41 days"));
$week_6_start_long = date('M j', strtotime("now +35 days"));
$week_6_end_long = date('M j', strtotime("now +41 days"));
};
//month following week 6 (month 7)
$month_7 = date('m', strtotime($week_6_end));
$month_7_start = date('Y-m-d', strtotime("$week_6_end_long +1 day"));
$month_7_end = date('Y-m-d', mktime(0, 0, 0, ($month_7 + 2), 0, $year));
$month_7_start_long = date('M j', strtotime("$week_6_end_long +1 day"));
$month_7_end_long = date('M j', mktime(0, 0, 0, ($month_7 + 2), 0, $year));
//Month 8
$month_8 = date('m', strtotime($month_7_end_long));
$month_8_start = date('Y-m-d', mktime(0, 0, 0, ($month_8 +1), 01, $year));
$month_8_end = date('Y-m-d', mktime(0, 0, 0, ($month_8 + 2), 0, $year));
$month_8_start_long = date('M j', mktime(0, 0, 0, ($month_8 +1), 01, $year));
$month_8_end_long = date('M j', mktime(0, 0, 0, ($month_8 + 2), 0, $year));
//Month 9
$month_9 = date('m', strtotime($month_8_end_long));
$month_9_start = date('Y-m-d', mktime(0, 0, 0, ($month_9 +1), 01, $year));
$month_9_end = date('Y-m-d', mktime(0, 0, 0, ($month_9 + 2), 0, $year));
$month_9_start_long = date('M j', mktime(0, 0, 0, ($month_9 +1), 01, $year));
$month_9_end_long = date('M j', mktime(0, 0, 0, ($month_9 + 2), 0, $year));
//Month 10
$month_10 = date('m', strtotime($month_9_end_long));
$month_10_start = date('Y-m-d', mktime(0, 0, 0, ($month_10 +1), 01, $year));
$month_10_end = date('Y-m-d', strtotime("$today_date +1 year"));
$month_10_start_long = date('M j', mktime(0, 0, 0, ($month_10 +1), 01, $year));
$month_10_end_long = date('M j\ \'y', strtotime("$today_date +1 year -2 days"));
// Events Page
$week_page = "http://www.mysite.com/week-";
//Echo Links
//Events by Week
echo "<h2 align=\"center\">$year Events</h2>";
echo "<h4 align=\"left\"><a href=\"http://www.mysite.com/events.php\">Upcoming Events</a></a></h4>";
echo "<p class=\"ENav\">";
echo "<a href=\"$week_page$week_1_start-thru-$week_1_end.html\">$week_1_start_long - $week_1_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$week_2_start-thru-$week_2_end.html\">$week_2_start_long - $week_2_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$week_3_start-thru-$week_3_end.html\">$week_3_start_long - $week_3_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$week_4_start-thru-$week_4_end.html\">$week_4_start_long - $week_4_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$week_5_start-thru-$week_5_end.html\">$week_5_start_long - $week_5_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$week_6_start-thru-$week_6_end.html\">$week_6_start_long - $week_6_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$month_7_start-thru-$month_7_end.html\">$month_7_start_long - $month_7_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$month_8_start-thru-$month_8_end.html\">$month_8_start_long - $month_8_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$month_9_start-thru-$month_9_end.html\">$month_9_start_long - $month_9_end_long</a>";
echo "<br />";
echo "<a href=\"$week_page$month_10_start-thru-$month_10_end.html\">$month_10_start_long - $month_10_end_long</a>";
echo "<br />";
echo "</p>";
Pumps out:
2008 Events
Upcoming Events
Aug 18 - Aug 24
Aug 25 - Aug 31
Sep 1 - Sep 7
Sep 8 - Sep 14
Sep 15 - Sep 21
Sep 22 - Sep 28
Sep 29 - Oct 31
Nov 1 - Nov 30
Dec 1 - Dec 31
Jan 1 - Aug 18 '09