WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple PHP control CSS Calender
Categories : PHP, HTML and PHP, Calendar, Date Time, CSS Click here to Update Your Picture
Vijit Patil
Date : Apr 26th 2007
Grade : 4 of 5 (graded 6 times)
Viewed : 4700
File : 4620.zip
Images : Image 1 , Image 2
Search : More code by Vijit Patil
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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
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
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
XDT Topsite (Gold v1.0)
Categories : Databases, CSS, PHP, HTML and PHP, Sessions
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Dynamic CSS generation for multiple website colouring schemes.
Categories : PHP, CSS, HTML and PHP
PHP alternating the colors of table rows with style.
Categories : PHP, HTML and PHP, CSS
A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed.
Categories : Date Time, PHP, Complete Programs, 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
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June).
Categories : Calendar, Date Time, PHP