In this example we are going to design a calender which will show the Date for any Month and Year.
The Calender is dynamic in nature and allows you to see next as well as previous month and also allows to directly jump to Today's date.
For that we define three veriables $ToDayDate, $PrevMonth, $NextMonth and assign them values of current, Previous and next month value with the php date() function.
Then we manupualte that data to generate the calender... please see details code.
<?php
if( !isset( $_REQUEST [ "CurrentMonth" ]) ) {
$ToDayDate = date ( "m/d/Y" );
}
else{
$ToDayDate = $_REQUEST [ 'CurrentMonth' ];
}
$PrevMonth = date ( "m/d/Y" , strtotime ( $ToDayDate . "-1 month" ));
$NextMonth = date ( "m/d/Y" , strtotime ( $ToDayDate . "+1 month" ));
$Today = date ( "j" , strtotime ( $ToDayDate ));
$DaysThisMonth = DaysInMonth ( date ( "m/d/Y" , strtotime ( $ToDayDate )));
$DaysLastMonth = DaysInMonth ( date ( "m/d/Y" , strtotime ( $PrevMonth )));
$CurrentMonth = 0 ;
$CurrentDate = GetStartingPoint ( $DaysLastMonth );
?>
<html>
<head><title>Calender</title></head>
<style type="text/css" media="all">
#dummy {
font-family:Trebuchet MS;
font-size: 9pt;
padding: 3px;
}
</style>
<body>
<table width="200" border="1" cellpadding="1" bordercolor="#FFFF66">
<tr>
<td>
<table bgcolor='B0C4DE' height='200' width='250' border='0' id="dummy"><tr>
<td colspan='7' height='8%'>
<table border='0' width='100%'><tr>
<td align='left'><a href='<?php echo "cal.php?CurrentMonth=" . $PrevMonth . "" ; ?> '><img src=page_left.gif width=16 height=16 alt=Previous_month /></a></td>
<td align='center'><font size='3'><b><?php echo date ( "F Y" , strtotime ( $ToDayDate )); ?> </b></font></td>
<td align='right'><b><font size='2'><a href='<?php echo "cal.php?CurrentMonth=" . $NextMonth . "" ; ?> '><img src=page_right.gif width=16 height=16 alt=next_month /></a></font></b></td></tr>
<tr><td align='center' colspan='3'><font size='2'><a href='<?php echo "cal.php?CurrentMonth=" . date ( "m/d/Y" ). "" ; ?> '>Today</a></font></td></tr></table>
</td></tr>
<td height='8%' align='center' valign='top' width='15%' bgcolor='FFFACD'><font size='2'><b>Sun</b></font></td>
<td align='center' valign='top' width='14%' bgcolor='FFFACD'><font size='2'><b>Mon</b></font></td>
<td align='center' valign='top' width='14%' bgcolor='FFFACD'><font size='2'><b>Tue</b></font></td>
<td align='center' valign='top' width='14%' bgcolor='FFFACD'><font size='2'><b>Wed</b></font></td>
<td align='center' valign='top' width='14%' bgcolor='FFFACD'><font size='2'><b>Thu</b></font></td>
<td align='center' valign='top' width='14%' bgcolor='FFFACD'><font size='2'><b>Fri</b></font></td>
<td align='center' valign='top' width='15%' bgcolor='FFFACD'><font size='2'><b>Sat</b></font></td></tr>
<?php
for( $x = 1 ; $x < 7 ; $x ++){
echo "<tr>" ;
for( $i = 1 ; $i < 8 ; $i ++){
echo "<td align='left' valign='top' height='14%' " ;
if( $CurrentMonth == 0 ){
echo "bgcolor='#D3D3D3'>" ;
echo $CurrentDate ++;
}
else{
if( $CurrentDate == date ( "j" ) && date ( "n" , strtotime ( $ToDayDate )) == date ( "n" ) && date ( "y" , strtotime ( $ToDayDate )) == date ( "y" ) ){
echo "bgcolor='FFFACD'>" ;
}
else{
echo "bgcolor='#FFFFFF'>" ;
}
echo $CurrentDate ++;
}
echo "</td>" ;
if( $CurrentMonth == 0 && $CurrentDate > $DaysLastMonth ){
$CurrentDate = 1 ;
$CurrentMonth = 1 ;
}
elseif( $CurrentMonth == 1 && $CurrentDate > $DaysThisMonth ){
$CurrentDate = 1 ;
$CurrentMonth = 0 ;
}
}
echo "</tr>" ;
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
<?php
function DaysInMonth ( $dt ) {
return date ( "t" , strtotime ( $dt ));
}
function GetStartingPoint ( $DLM ){
$today = getdate ( strtotime ( $GLOBALS [ 'ToDayDate' ]));
$mday = $today [ 'mday' ];
$mday -= 1 ;
$FirstOfMonth = date ( "m/d/Y" , strtotime ( $GLOBALS [ 'ToDayDate' ] . "-" . $mday . " days" ));
switch( date ( "l" , strtotime ( $FirstOfMonth ))){
case "Sunday" :
$CD = 1 ;
$GLOBALS [ "CurrentMonth" ] = 1 ;
break;
case "Monday" :
$CD = $DLM ;
break;
case "Tuesday" :
$CD = $DLM - 1 ;
break;
case "Wednesday" :
$CD = $DLM - 2 ;
break;
case "Thursday" :
$CD = $DLM - 3 ;
break;
case "Friday" :
$CD = $DLM - 4 ;
break;
case "Saturday" :
$CD = $DLM - 5 ;
}
return $CD ;
}
function GetThisDate ( $SelectedDay ){
$today = getdate ( strtotime ( $GLOBALS [ 'WorkDate' ]));
$mon = $today [ 'mon' ];
$myear = $today [ 'year' ];
return date ( "m/d/Y" , strtotime ( $mon . "/" . $SelectedDay . "/" . $myear ));
} ?>
CALENDAR - easy calendar-navigation with PHP Categories : PHP , Date Time , HTML and PHP , Calendar Kewl Date Example Categories : PHP , HTML and PHP , Date Time , CSS , Beginner Guides Customizable Calendar Class Categories : HTML and PHP , Date Time , PHP , PHP Classes , Calendar PHP Calendar Categories : PHP , Calendar , Date Time , Java Script , CSS This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time. Categories : PHP , Calendar , Date Time , HTML and PHP Calendar using Date function Categories : HTML and PHP , PHP , Date Time , Calendar Calendar class on the same page , suitable for reservation
Categories : PHP , Calendar , Date Time Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP , PHP , Date Time Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays. Categories : Calendar , Date Time , PHP , Databases , MySQL If you want to create select buttons featuring current date this example will show you how... Categories : Date Time , HTML and PHP , PHP table calendar pretty much does what cal(1) does - prints out a calendar.
Categories : Date Time , PHP , Calendar Local-to-user date and time display regardless of time zone or where the website's server is located Categories : PHP , Date Time , HTML and PHP , Java Script Dynamic Calendar in PHP, Javascript and HTML. Categories : PHP , Java Script , HTML and PHP , Calendar XDT Topsite (Gold v1.0) Categories : Databases , CSS , PHP , HTML and PHP , Sessions Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps. Categories : HTML and PHP , PHP , MySQL , Date Time