Zend - The PHP Company




Calendars

Add Code


Year Calender  

Type: code fragment
Added by: ranga
Entered: 04/01/2001
Last modified: 01/12/2000
Rating: **** (7 votes)
Views: 11075
You can see the year calender and it will highlight the current date according to the local time


<HTMl>
<TITLE> YEAR CALENDER </TITLE>
<BODY>
<?
        $month_len
=array( 1=>31,28,31,30,31,30,31,31,30,31,30,31 );
        
$days_of_week=array(1=>"S","M","T","W","T","F","S");
        
$currentmonth=date("m");
        
$currentdate=date("d");

        if(
$cyear==''){
                
$cyear=date("Y");
        }else{
                
$cyear=$cyear;
        }
        
$py=$cyear-1;
        
$ny=$cyear+1;

        function 
isleap($ilyear){
                
/* Rules:
                1. Year is leap year if year is equally divisible by 4
                2. Century years are not leap years (generally)
                3. Century years equally divisible by 400 are leap years */
                
$leap=0;
                if(
$ilyear/4==intval($ilyear/4)) { // rule #1
                        
$leap=1;
                if(
$ilyear/100==intval($ilyear/100)) { // rule #2
                        
$leap=0;                  // does not have 29th day
                        
if($ilyear/400==intval($ilyear/400))              // rule #3
                        
$leap=1;
                        }
                }
                        return 
$leap;
        }


?>
<TABLE align="center">
        <TR>
                <TD><A href="calender.php?cyear=<? echo $py ?>"><B><<&nbsp;Pre</B></A></TD>
                <TD><?echo $cyear ?></TD>
                <TD><A href="calender.php?cyear=<? echo $ny ?>"><B>Next&nbsp;>></B></A></TD>
        </TR>
</TABLE>


<?
        
echo "<TABLE align="center" width="40%" border="1" cellspacing="0" cellpadding="0">";
        
$mon=1;
        for(
$row=1;$row<=3;$row++){
                echo 
"<TR>";
                        for(
$col=1;$col<=4;$col++){
                                echo
"<TD width="40%" valign="top">";
                                echo
"<TABLE bgcolor="#ffffff" width=="30%" border="0"  cellspacing="2" cellpadding="1">";
                                        
echo"<TR>";
                                                echo 
"<TD colspan="7"  align="center" ><B>";
                                                echo 
date("F",mktime(0,0,0,$mon,1,$cyear));
                                                echo 
"</B></TD>";
                                        echo
"</TR>";
                                        echo 
"<TR>";
                                                for(
$d=1;$d<=7;$d++){
                                                        if(
$d==1){
                                                                
$fcolor="red";
                                                        }else{
                                                                
$fcolor="Black";
                                                        }
                                                        echo
"<TD align="center"><FONT color=$fcolor>$days_of_week[$d]</FONT></TD>";
                                                }
                                        echo
"</TR>";
                                        echo
"<TR>";
                                        
$month=$month_len[$mon];
                                        if(
$mon==2){
                                                        
$month+=isleap($cyear);
                                        }
                                        
$day = (date("w"mktime(0,0,0,$mon,1,$cyear))+1);
                                        if(
$day>1){
                                                for(
$i=1$i<$day;$i++){
                                                        echo 
"<TD>&nbsp;</TD>";
                                                }
                                        }
                                        
$start=$day;
                                        
$exit=1;
                                        
$date=1;
                                                while(
$exit){
                                                        for(
$f=$start;$f<=7;$f++){
                                                                if(
$f==1){
                                                                        
$fcolor="red";
                                                                }else{
                                                                        
$fcolor="Black";
                                                                }

                                                                if(
$date==$currentdate && $mon==$currentmonth){
                                                                        echo
"<TD bgcolor="yellow"><FONT color=$fcolor SIZE="-1">$date</FONT></TD>   ";
                                                                }else{
                                                                        echo 
"<TD align="center"><FONT color=$fcolor SIZE="-1">$date</FONT></TD>";
                                                                }
                                                                
$date++;
                                                                if(
$date>$month){
                                                                        
$exit=0;
                                                                        if(
$f<7)
                                                                                 for(
$next_mo=1;$next_mo+$f<=7;$next_mo++){
                                                                                        echo
"<TD>&nbsp;</TD>";
                                                                                }
                                                                        
$day=$f;

                                                                        if(++
$day>7)
                                                                                
$day=1;
                                                                                break;
                                                                }
                                                        }
                                                        
$start=1;
                                                        echo 
"</TR>";

                                                if(
$exit)
                                                        echo
"<TR>";
                                                }
                                echo
"</TABLE>";
                                echo
"</TD>";
                                
$mon++;
                        }
//$col end..............
                
echo"</TR>";
        }
//$row End...............
        
echo "</TABLE><P><P>";
?>
</BODY>
</HTML>



Usage Example




Rate This Script





Search



This Category All Categories