Date Time Php


## change to the previous month
if ($command == "prev_month")
{
if (--$month == 0)
{
$month = 12;
$year--;
}
}
## change to the next month
else if ($command == "next_month")
{
if (++$month == 13)
{
$month = 1;
$year++;
}
}
## if no month has been passed
if ($month == "")
{
$year= date("Y");
$month= date("n");
$month_name = date("F",mktime(0,0,0,$month,1,$year));
}
## use current date if no month is passed
else
{
$year= date("Y",mktime(0,0,0,$month,1,$year));
$month= date("n",mktime(0,0,0,$month,1,$year));
$month_name = date("F",mktime(0,0,0,$month,1,$year));
}
$dow = date("w",mktime(0,0,0,$month,1,$year)); //which day 1 falls on in the week
(0 = Sun)
$dim = date("d",mktime (0,0,0,$month+1,0,$year)); //days in the current month
## modification to only print the number of weeks in a month
$wim = ceil(($dim+$dow)/7); //weeks in month
$ct=0;
echo "





<< $month_name $year href='index.php?command=next_month&month=$month&year=$year'>>>












";
## print only the number of weeks needed
for($row=1;$row<$wim+1;$row++)
{
echo "";
## prints week (Sun to Sat)
for($week=1;$week<8;$week++)
{
$ct++;
$value=mktime(0,0,0,$month,$ct-$dow,$year);
## if $value is part of current month
if (date("m",$value)==$month)
{
echo "
";
}
## print previous and next month dates, but grayed out
else
{
echo "";
}
}
echo "";
}
echo "
Sun Mon Tue Wed Thu Fri Sat

".date("j",$value)."


bgcolor='#CCCCCC'>
align='right'>".date("j",$value)."

";
?>