note 53237 deleted from function.date by aidan
| From: | aidan@php.net | Date: | Sun, 31 Jul 2005 12:34:16 +0000 |
| Subject: | note 53237 deleted from function.date by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92820@lists.php.net to get a copy of this message | ||
Note Submitter: nikhil at nikhilzkingdom dot com
----
Function to display the current month calender as a table.
You can optionally change the $year, $month to which ever month you wish.Hope this helps
function displayCurrentMonthCalenderAsTable()
{
// Find the first day of the current month
$year=date("Y"); // this year
$month=date("n"); // this month
$day=1; // start from first of month
$month_caption=date("M $year"); // caption to table
print "<table summary=\"Monthly calendar\">
<caption>$month_caption</caption>
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>\n";
$ts = mktime(0,0,0,$month,$day,$year); // unix timestamp of the first day of current month
$weekday_first_day = date("w",$ts); // which is the weekday of the first day of week
0-Sunday 6-Saturday
$slot=0;
print "<tr>\n"; // First row starts
for($i=0;$i<$weekday_first_day;$i++) // Pad the first few rows(slots)
{
print " <td></td>"; // Empty slots
$slot++;
}
while(checkdate($month,$day,$year) && $date<32) // till there are valid days in current
month
{
if($slot == 7) // if we moved past saturday
{
$slot = 0; // reset and move back to sunday
print "</tr>\n"; // end of this row
print "<tr>\n"; // move on to next row
}
echo " <td>$day</td>"; // print the day
$day++;
$slot++;
}
if($slot>0) // have we started off a new last row
{
while($slot<7) // padding at the end to complete the last row table
{
print " <td></td>"; // empty slots
$slot++;
}
print "\n</tr>\n"; // close out last row
}
print '</table>'; //end of table
}
displayCurrentMonthCalenderAsTable();