I am relatively new to PHP. I create a simple calendar script, but I've discovered an error. It was 10:52pm EST(UTC -5) on Thursday, Jul 17 2012 realtime, but my program was saying it was Jul 18 2012. I figure it's something with the date() that I'm not doing right, but I'm not sure. Perhaps someone can help me out? I'll post the script below....
<?php
/* Calendar Begin */
$current_day_name = date(l);
$current_day_short_name = date(D);
$current_day_num = date(d);
$current_day_suffix = date(S);
$current_month_name = date(F);
$current_month_num = date(n);
$current_year = date(Y);
$current_month_total_days = cal_days_in_month(CAL_GREGORIAN,$current_month_num,$current_year);
$current_month_first_day = mktime(0,0,0,$current_month_num,1,$current_year);
$current_month_first_day_name = date('D',$current_month_first_day);
$days_in_week = 1;
$days_in_month = 1;
switch ($current_month_first_day_name) {
case "Sun": $empty_cell = 0; break;
case "Mon": $empty_cell = 1; break;
case "Tue": $empty_cell = 2; break;
case "Wed": $empty_cell = 3; break;
case "Thu": $empty_cell = 4; break;
case "Fri": $empty_cell = 5; break;
case "Sat": $empty_cell = 6; break; }
echo "<font size='5'><i>".$current_month_name." - ".$current_year."</i></font>";
echo "<table border='1'>";
echo "<tr>
<th width='70' height='30'>Sun</th>
<th width='70'>Mon</th>
<th width='70'>Tue</th>
<th width='70'>Wed</th>
<th width='70'>Thu</th>
<th width='70'>Fri</th>
<th width='70'>Sat</th></tr>";
echo "<tr>";
while ($empty_cell > 0) {
echo "<td height='50'><p align='center'> --- </p></td>";
$days_in_week++;
$empty_cell--; }
while ($days_in_month <= $current_month_total_days) {
echo "<td height='50'><p align='center'>".$days_in_month."</p></td>";
$days_in_month++;
$days_in_week++;
if($days_in_month == $current_day_num) {
echo "<td height='50'><p align='center'><font color='red'><b>".$days_in_month."</b></font></p></td>";
$days_in_month++;
$days_in_week++; }
if ($days_in_week > 7) {
echo "<tr></tr>";
$days_in_week = 1; } }
echo "</tr></table>";
/* Calendar End */
echo $current_day_name;
?>
If anyone can be any help, it'd be greatly appreciated.
jiveTurkey420