|
|
|
|
|
|
| |
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));
}?> | | |
|
| 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 - easy calendar-navigation with PHP Categories : PHP, Date Time, HTML and 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 | | | php html calendar dynamic Categories : HTML and PHP, PHP, Calendar | | | 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 | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Shows the current time as a PNG-image. This script does not use the GD
library. You can use it as a benchmark (because it's slow), or as a quick
reference for implementing a simple PNG-file generator. Categories : Graphics, Zlib, Calendar, PHP, Date Time | | | enhanced date picker with jcript checking for a dynamic date input Categories : PHP, Java Script, Date Time, Calendar, Arrays | |
|
|