A Digital Age Deserves A Digital Leader

php calendar help please!

php calendar help please!

Postby xion`silo » Mon Jun 09, 2008 3:54 am

so does anyone know how to display the current week only in PHP? I wrote a calendar script but i cannot get it to display or figure out a way to display only the current week. :( I really wanna figure this out or my head is gonna explode. please help :)
Code: Select all
//This gets today's 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, $month, 1, $year);
      // Here we generate the first day of the week
      //$first_day = mktime(0, 0, 0, $month, $day, date("Y")) - (date("N")*3600*24);
      //echo date("l jS F, Y @ H:i:s a", $week);
      //echo(strtotime('monday', $date));

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

      $day_of_week = date('D', $first_day);

      //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
      switch ($day_of_week)
      {
         case "Sun":
            $blank = 0;
            break;
         case "Mon":
            $blank = 1;
            break;
         case "Tue":
            $blank = 2;
            break;
         case "Wed":
            $blank = 3;
            break;
         case "Thu":
            $blank = 4;
            break;
         case "Fri":
            $blank = 5;
            break;
         case "Sat":
            $blank = 6;
            break;
      }

      //We then determine how many days are in the current month
      $days_in_month = cal_days_in_month(0, $month, $year);

      echo "<table>";
      echo "<tr><th> $title $year </th></tr>";
      echo "<tr>
      <td>S</td>
      <td>M</td>
      <td>T</td>
      <td>W</td>
      <td>T</td>
      <td>F</td>
      <td>S</td>
   </tr>";

      //This counts the days in the week, up to 7
      $day_count = 1;

      echo "<tr>";
      //first we take care of those blank days
      while ($blank > 0)
      {
         echo "<td></td>";
         $blank = $blank - 1;
         $day_count++;
      }

      //sets the first day of the month to 1
      $day_num = 1;

      //count up the days, untill we've done all of them in the month
      while ($day_num <days_in_month>formatTask($numTasks)."</a></div></td>";
         $day_num++;
         $day_count++;

         //Make sure we start a new row every week
         if ($day_count > 7)
         {
            echo "</tr><tr>";
            $day_count = 1;
         }
      }
      //Finaly we finish out the table with some blank details if needed
      while ($day_count > 1 && $day_count <= 7)
      {
         echo "<td> </td>";
         $day_count++;
      }

      echo "</tr></table>";
PRO New Member
Posts: 9
Joined: Mon Jun 02, 2008 5:27 am
Location: Austin, TX

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests