php  calendar is one of the important think in web programming,  It will be helpful in many occations  Like online booking, many online translation ect.
If you are dealing with php websites there may be many occasion that you may need php calendar.

create simple php calendar

Let us check how we can create simple php calendar.
What I’m going to show now is creating a php calendar using  php codes and html
i’m using inbuilt php date functions to create the dates.
Lets enter into coding.


<?php

$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");

if (!isset($_GET["m"])) $_GET["m"] = date("n");
if (!isset($_GET["y"])) $_GET["y"] = date("Y");

$currentMonth = $_GET["m"];
$currentYear = $_GET["y"];

$p_year = $currentYear;
$n_year = $currentYear;
$p_month = $currentMonth-1;
$n_month = $currentMonth+1;

if ($p_month == 0 ) {
    $p_month = 12;
    $p_year = $currentYear - 1;
}

if ($n_month == 13 ) {
    $n_month = 1;
    $n_year = $currentYear + 1;
}
$days=array('1'=>"S",'2'=>"M",'3'=>"T",'4'=>"W",'5'=>"T",'6'=>"F",'7'=>"S");

?>

<table width="800">
<tr align="center">
<td bgcolor="#7DC3E3" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?m=". $p_month . "&y=" . $p_year; ?>" style="color:#FFFFFF">Prev</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?m=". $n_month . "&y=" . $n_year; ?>" style="color:#FFFFFF">Next</a>  </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%"  border="1" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#7DC3E3" style="color:#FFFFFF"><B><?php echo $monthNames[$currentMonth-1].' '.$currentYear; ?></B></td>
</tr>
<tr >
<?php for($i=1;$i<=7;$i++){ ?>

<td align="center" height='100' bgcolor="#7DC3E3" style="color:#FFFFFF"><B><?php echo $days[$i]; ?></B></td>

<?php } ?>
</tr>
<?php
$timestamp = mktime(0,0,0,$currentMonth,1,$currentYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
    if(($i % 7) == 0 ) echo "<tr>";
    if($i < $startday) echo "<td ></td>";
    else echo "<td align='center'    height='80' valign='middle' bgcolor='#AED5E4' height='20px'>". ($i - $startday + 1) . "</td>";
    if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>

Download                                                    Labs