Holiday Planner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sidders
    New Member
    • Jun 2007
    • 4

    Holiday Planner

    Hi, I am trying to build a holiday planner and need to be able to overcome a problem with my output with the dates. I have manipulated a calendar script to output days of the month in columns, (1 2 3 4 5 6 etc) This works fine when the month is input it shows exact days for that month. What I cannot do is repeat this for the days of the month ie M T W T F and so on. Does anyone have any
    1 2 3 4 5
    idea how I can relove this issue.

    Regards Sid
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, sidders. Welcome to TSDN!

    Originally posted by sidders
    This works fine when the month is input it shows exact days for that month. What I cannot do is repeat this for the days of the month ie M T W T F and so on.
    I'm not sure I understand what you're asking. Do you want to output day-of-the-week headers for your calendar? Or do you need to determine which day of the week a given date is?

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      PHP has built in functions for dealing with dates, including the ability to get the day of the week.

      Comment

      • epots9
        Recognized Expert Top Contributor
        • May 2007
        • 1352

        #4
        u do only want to display Monday to Friday, excluding Suturday and Sunday?

        Comment

        • sidders
          New Member
          • Jun 2007
          • 4

          #5
          Hi again, well what I am looking for is similar to the normal calendar output which shows S M T W T F S, however instead of dropping to the next row I need it to continue along the columns until it reaches the end of the month so the table will look like S M T W T F S S M T W T F S S M T W T F S etc. I have the columns of numbers but not the day headers above. I have posted some code below as to where my problem lies. The code below is just the basic structure, for obvious reasons I have stripped out all the SQL

          Thanks in advance Sidders.
          [code=php]
          <?

          if(isset($todo) and $todo=="submit" ){
          $date_value="$m onth/$dt/$year";
          echo "mm/dd/yyyy format :$date_value<br >";
          $date_value="$y ear-$month-$dt";
          echo "YYYY-mm-dd format :$date_value<br >";
          }

          $Month = $_GET['month'];
          $Year = $_GET['year'];

          //echo $Month;
          //echo $Year;


          //This gets todays date
          $date =time ();

          //This puts the day, month, and year in seperate variables
          $day = date('d', $date);
          $month = date('m', $date);
          $year = date('Y', $date);

          //Here we generate the first day of the month
          $first_day = mktime(0,0,0,$m onth, 1, $year);

          //This get's us the month name
          $title = date('F', $first_day);

          //Here we find out what day of the week the first day of the month falls on
          $day_of_week = date('D', $first_day);

          echo $day_of_week;

          ?>
          <html>
          <body>
          <form method='GET' name='Form1' action='<? $_SERVER['PHP_SELF'];?>'>
          <table border="0" cellspacing="0" >
          <tr><td align=left >
          </select>&nbsp;&n bsp;&nbsp;
          <select name=month value=''>Select Month</option>
          <option value='01'>Janu ary</option>
          <option value='02'>Febr uary</option>
          <option value='03'>Marc h</option>
          <option value='04'>Apri l</option>
          <option value='05'>May</option>
          <option value='06'>June </option>
          <option value='07'>July </option>
          <option value='08'>Augu st</option>
          <option value='09'>Sept ember</option>
          <option value='10'>Octo ber</option>
          <option value='11'>Nove mber</option>
          <option value='12'>Dece mber</option>
          </select>

          </td><td align=left >
          Year(yyyy)<inpu t type=text name=year size=4 value=2005>
          <input type=submit value=Submit>
          </table>
          </form>
          <?

          function showMonth($mont h, $year)
          {
          $date = mktime(12, 0, 0, $month, 1, $year);
          $daysInMonth = date("t", $date);
          // calculate the position of the first day in the calendar (sunday = 1st column, etc)
          $offset = date("w", $date);
          //echo $offset;
          $rows = 1;
          $dateDay=cal_to _jd(CAL_GREGORI AN,date("m"),da te("d"),date("Y "));
          $ddate = (jddayofweek($d ateDay,2));
          echo $ddate;
          //for($ddate = 1; $ddate <= $offset; $ddate++)
          function myfunction()
          {
          for($i = 1; $i != 31; $i++)
          echo $ddate;
          }
          ?>
          <h1>Displayin g calendar for <? date("F Y", $date); ?> </h1>
          <table border="1">

          <tr>
          <td bgcolor="#66666 6"><?
          echo $_GET['action'];
          ?> </td>
          <?

          for($i = 1; $i <= $daysInMonth; $i++)
          {
          ?>
          <td>
          <?
          myfunction() ?>&nbsp;</td>
          <?
          }
          while( ($i + $offset) <= $rows )
          {
          ?>
          <td></td>
          <?
          $i++;
          }
          ?>

          </tr><tr>
          <td bgcolor="#66666 6">&nbsp; </td>
          <?
          for($day = 1; $day <= $daysInMonth; $day++)
          {
          ?>
          <td>
          <? echo $day; ?> </td>
          <?
          }
          while( ($day + $offset) <= $rows )
          {
          ?>
          <td></td>
          <?
          $day++;
          }
          ?>
          </tr>
          </table>
          <?
          }
          ?>
          Displaying the calendar in a page
          To display it in a HTML page, you just need to include a call to the showMonth() function, passing the desired month and year as paramters.
          For example:
          <?
          showMonth($Mont h, $Year); // July 2005
          //showMonth(1, 1980); // January 1980
          // showMonth(12, 2012); // December 2012 ?>
          </body>
          </html>
          [/code]
          Last edited by Atli; Jun 18 '07, 11:18 AM. Reason: Added [CODE] tags.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            I am sorry, but I couldn't entirely follow what you were trying to do with your code. Could you please elaborate on what you are trying to do, as well as give the errors you are receiving and detail what is going wrong?

            Comment

            • sidders
              New Member
              • Jun 2007
              • 4

              #7
              Hi ok sorry if it a little bit unclear, I will try to get this a simple as possible. A normal calendar out puts 7 days then adds the rows accordingly. I want the planner to show the month dates in line like my code already does. What I want and cannot yet do is to show the day above the day number so for instance June the 1st would be F(Friday) above the 1 and then so forth until S(Saturday) above the 30 in the column. Hope that explains it a little more.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                So you want to be able to create a calendar with != 7 columns? Or put another way, you want to be able to put every single day of a month on one row? Is this correct?

                Comment

                • sidders
                  New Member
                  • Jun 2007
                  • 4

                  #9
                  Originally posted by pbmods
                  So you want to be able to create a calendar with != 7 columns? Or put another way, you want to be able to put every single day of a month on one row? Is this correct?
                  Yes that is correct, what it will be able to do is print a list of names that have holidays in that month I can then cross reference graphically the days people overlap with holidays similar to a gantt chart.

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by sidders
                    Hi ok sorry if it a little bit unclear, I will try to get this a simple as possible. A normal calendar out puts 7 days then adds the rows accordingly. I want the planner to show the month dates in line like my code already does. What I want and cannot yet do is to show the day above the day number so for instance June the 1st would be F(Friday) above the 1 and then so forth until S(Saturday) above the 30 in the column. Hope that explains it a little more.
                    The following code returns an associative array for the month you specify. The array index is the day of the month, and the value is the three letter representation of the day of the week.

                    [code=php]
                    function buildMonth($mon th, $year)
                    {
                    $ret = array();
                    for($i = 1; $i <= mcal_days_in_mo nth($month, $year); $i++)
                    {
                    $ret[i] = date('D', mktime(0, 0, 0, $month, $i, $year));
                    }
                    return $ret;
                    }
                    [/code]

                    Comment

                    Working...