Dark-Hawk Posted April 7, 2009 Share Posted April 7, 2009 I'm trying to make a dedicated calendar for a PHP application for a school. The calendar needs to always display a particular month since their Parent Teacher Conferences never change. How would I force the calendar I've put together to ALWAYS display, let's say the month of December, if it's currently June. This is the calendar script I'm currently building off of, I figured it'd be much easier to build off of just a calendar, rather than worry about putting that together on my own as well: <? /* Print out the HTML headers, and calendar header */ echo "<HTML>\n" . " <HEAD>\n" . " </head>\n" . " <BODY>\n"; /* Grab the month and year */ if ($month == "" || $year == "") { $this_month = date("n"); $month_name = date("F"); $this_year = date("Y"); } else { $this_month = date("n", mktime(0, 0, 0, $month, 1, $year)); $month_name = date("F", mktime(0, 0, 0, $month, 1, $year)); $this_year = date("Y", mktime(0, 0, 0, $month, 1, $year)); } /* This is for the navigation */ $last_month = $this_month - 1; $next_month = $this_month + 1; /* Same with all this stuff */ if ($last_month == 12) $last_year = $this_year - 1; else $last_year = $this_year; /* DITTO!!! */ if ($next_month == 1) $next_year = $this_year + 1; else $next_year = $this_year; /* Display the calendar header */ echo " <CENTER><B>Event Calendar for $month_name, $this_year</b></center><BR>\n" . " <TABLE align=\"center\" border=\"2\" bordercolor=\"#000000\" cellpadding=\"5\" cellspacing=\"0\">\n" . "<TR bgcolor=\"#DDDDDD\">\n" . "<TH width=\"115\">Sun</th>\n" . "<TH width=\"115\">Mon</th>\n" . "<TH width=\"115\">Tue</th>\n" . "<TH width=\"115\">Wed</th>\n" . "<TH width=\"115\">Thu</th>\n" . "<TH width=\"115\">Fri</th>\n" . "<TH width=\"115\">Sat</th>\n" . "</tr>\n"; /* Grab the first day of the month, and total days */ $first_day = date("w", mktime(0, 0, 0, $this_month, 1, $this_year)); $total_days = date("t", mktime(0, 0, 0, $this_month, 1, $this_year)); /* Start on the day of the first week */ $week_num = 1; $day_num = 1; /* While the day of the week isn't '7' */ while ($week_num <= 6) { echo "<TR>\n"; /* Loop through the week days */ for ( $i = 0; $i <= 6; $i++ ) { /* If it's the first week then... */ if ($week_num == 1) { /* If it's not the first day yet, then use a space */ if ($i < $first_day) $the_day = " "; /* If it is the first day, then start with a '1' */ else if ($i == $first_day) { $the_day = 1; } } else { /* If we're past the total days, then use spaces */ if ($the_day > $total_days) $the_day = " "; } /* Display the day (or space) */ echo "<TD height=\"150\" width=\"110\" valign=\"top\"></style><font size=3>\n"; /* Incrememnt the day of the month */ if ($the_day != " "); { echo '<a href="edcal.php?'; //adding the link to the date in each cell echo "the_day=$the_day"; echo "&this_year=$this_year"; echo "&this_month=$month_name"; echo "&month=$this_month"; echo "&year=$this_year"; echo '">'; echo "$the_day"; echo '</a>'; echo "\n"; //$grab = ($the_day++); if(file_exists("$month_name$the_day$this_year.php")){ //checking for the data, if any include("$month_name$the_day$this_year.php"); } }$the_day++; } echo "\n"; echo '</td></tr>'; echo "\n"; /* Increment the week number */ $week_num++; } /* Finish off with closing out our tags */ echo "\n"; echo '</table><BR><CENTER><A href="calendar.php?month='; echo "\n"; echo "$last_month&year=$last_year"; echo "\n"; echo '">Last Month</a> || <A href="calendar.php?month='; echo "\n"; echo "$next_month&year=$next_year"; echo "\n"; echo '">Next Month</a>'; echo "\n"; echo '</center></body></html>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/152995-solved-force-month/ Share on other sites More sharing options...
Brian W Posted April 7, 2009 Share Posted April 7, 2009 Look into strtotime() to produce a Unix time stamp which you then would use as the second parameter in date() Example: <?php $time = strtotime("December 1st"); echo date("m-d-y", $time); ?> which outputs 12-01-09 Quote Link to comment https://forums.phpfreaks.com/topic/152995-solved-force-month/#findComment-803610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.