note 72549 added to function.date
| From: | kriswarner at solidaritymail dot com | Date: | Wed, 24 Jan 2007 05:40:32 +0000 |
| Subject: | note 72549 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122097@lists.php.net to get a copy of this message | ||
Here's a useful bit of code - I took Mushy's code for
displaying a calendar, and added links for viewing previous
and next months, so you can go ahead or backwards as many months as you like, one month at a time.
Basically the top row is changed, and looks like:
December (prev) January February (next)
Here it is:
<?
//determining action, current month and year
$action = $_REQUEST['action'];
if (!$action) //first page, set current_month variable = current month
{
$current_month = date("m"); //value will change if the user changes the month they are
viewing
$current_year = date('Y');
}
else //if user selected to go to previous or next month, reset current_month variable
{
$current_month = $_REQUEST['current_month'];
$current_year = $_REQUEST['current_year'];
if ($action == 'prev')
{
$current_month = date('m', mktime(0, 0, 0, $current_month-1));
//if going from january to december, change year as well
if ($current_month == '12')
{
$current_year = date('Y', mktime(0, 0, 0, $current_month, 1, $current_year-1));
}
}
if ($action == 'next')
{
$current_month = date('m', mktime(0, 0, 0, $current_month+1));
//if going from december to january, change year as well
if ($current_month == '01')
{
$current_year = date('Y', mktime(0, 0, 0, $current_month, 1, $current_year+1));
}
}
}
$previous_month = date('F', mktime(0, 0, 0, $current_month-1, date("d"),
date("Y")));
$next_month = date('F', mktime(0, 0, 0, $current_month+1, date("d"),
date("Y")));
$theday = date(w, mktime(0, 0, 0, $current_month, 1, $current_year));
$daysinmonth = date("t", mktime(0, 0, 0, $current_month, 1, $current_year));
echo "<table border=1 width=90%>";
echo "<tr><td><a
href=$PHP_SELF?action=prev¤t_month=".$current_month."
¤t_year=".$current_year.">$previous_month</a></td>
<td colspan=5 align=center>".date('F Y', mktime(0, 0, 0, $current_month, 1,
$current_year))."</td>
<td><a href=$PHP_SELF?action=next¤t_month=".$current_month."
¤t_year=".$current_year.">$next_month</a></td></tr>";
echo "<tr>";
echo "<td>Sunday</td>";
echo "<td>Monday</td>";
echo "<td>Tuesday</td>";
echo "<td>Wednesday</td>";
echo "<td>Thursday</td>";
echo "<td>Friday</td>";
echo "<td>Saturday</td>";
echo "</tr>";
echo "<tr>";
for ($i=0;$i<$theday;$i++)
{
echo "<td> </td>";
}
for ($list_day=1;$list_day<=$daysinmonth;$list_day++)
{
echo "<td>" . $list_day . "</td>";
if ($theday == 6)
{
echo "</tr>";
echo "<tr>";
$theday = -1;
}
$theday++;
}
echo "</tr>";
echo "</table>";
?>
----
Server IP: 216.194.113.175
Probable Submitter: 71.72.37.152
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/72549
Del: integrated -- https://master.php.net/note/delete/72549/integrated
Del: useless -- https://master.php.net/note/delete/72549/useless
Del: bad code -- https://master.php.net/note/delete/72549/bad+code
Del: spam -- https://master.php.net/note/delete/72549/spam
Del: non-english -- https://master.php.net/note/delete/72549/non-english
Del: in docs -- https://master.php.net/note/delete/72549/in+docs
Del: other reasons-- https://master.php.net/note/delete/72549
Reject -- https://master.php.net/note/reject/72549
Search -- https://master.php.net/manage/user-notes.php