Any idea how to get a new line for each week?
Currently my simple calendar script below only lists out all the days in the month on one line.

 <?php
$num_of_days_in_month  = date("t");
$current_day = date("j");

for($i=1; $i<=$num_of_days_in_month; $i++) {
    if($current_day==$i) {
        echo "<b>".$i."</b> | ";
    }
    else {
        echo $i." | ";
    }
}
?> 

    Hi there Chris!

    Using JDDayOfWeek will get you what you want:

    <?php
    $num_of_days_in_month  = date("t");
    $current_day = date("j");
    
    for($i=1; $i<=$num_of_days_in_month; $i++) {
    	$weekday = jddayofweek ( cal_to_jd(CAL_GREGORIAN, date("m"), $i, date("Y")), 0);
    	if($weekday == 0){
    		echo '<br><br>';
    	}
    	if($current_day==$i) {
    	echo "<b>".$i."</b> | ";
    	}else{
    		echo $i." | ";
    	}
    }
    
    ?>

    You can make it much prettier by dropping it into a table, aligning right so all dates sit where they should be, etc. but this gets you new lines at the start of the week.

      Thanks. I put it in a table as you said. Works great!

      <?php
      $num_of_days_in_month  = date("t");
      $current_day = date("j");
      $start = date("N");
      
      echo strftime("%b %Y");
      echo "<table><tr><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td><td>Sun</td></tr><tr>";
      
      if($start > 1) {
          echo "<td colspan=".($start-1).">&nbsp;</td>";
      }
      
      for($i=1; $i<=$num_of_days_in_month; $i++) {
              $weekday = jddayofweek ( cal_to_jd(CAL_GREGORIAN, date("m"), $i, date("Y")), 0);
              if($weekday == 1){
                      echo "</tr><tr>";
              }
              if($current_day==$i) {
                      echo "<td><b><font color=red>".$i."</font></b></td>";
              }
              else {
                      echo "<td>".$i."</td>";
              }
      }
      echo "</tr></table>";
      ?>
      
        5 days later

        Constantly trying to improve my calendar script. Now I want it to also show week numbers.
        Currently it's showing the current week number for all weeks. Any idea how I can correct this so it will show the week numbers correctly?

        <?php
        $num_of_days_in_month  = date("t");
        $current_day = date("j");
        $start = date("N");
        
        echo "<table border=1><tr><td colspan=7>" . strftime("%B %Y | %R %P") . "</td></tr>";
        
        $wdays = array('w','Mon','Tue','Wed','Thu','Fri','Sat','Sun');
        echo "<tr>";
        foreach($wdays as $wday) {
                echo "<td bgcolor=lightblue>" . $wday . "</td>";
        }
        echo "</tr><tr>";
        
        if($start > 1) {
            echo "<td colspan=".($start-1).">&nbsp;</td>";
        }
        
        for($i=1; $i<=$num_of_days_in_month; $i++) {
                $weekday = jddayofweek ( cal_to_jd(CAL_GREGORIAN, date("m"), $i, date("Y")), 0);
                if($weekday == 1){
                        echo "</tr><tr><td bgcolor=orange>".strftime('%V',strtotime('today'))."</td>";
                }
                if($current_day==$i) {
                        echo "<td><b>".$i."</b></td>";
                }
                else {
                        echo "<td>".$i."</td>";
                }
        }
        echo "</tr></table>";
        ?>
        
          <?php
          $num_of_days_in_month  = date("t");
          $current_day = date("j");
          $start = date("N");
          
          echo "<table border=1><tr><td colspan=7>" . strftime("%B %Y | %R %P") . "</td></tr>";
          
          $wdays = array('w','Mon','Tue','Wed','Thu','Fri','Sat','Sun');
          echo "<tr>";
          foreach($wdays as $wday) {
                  echo "<td bgcolor=lightblue>" . $wday . "</td>";
          }
          echo "</tr><tr>";
          
          if($start > 1) {
              echo "<td colspan=".($start-1).">&nbsp;</td>";
          }
          
          for($i=1; $i<=$num_of_days_in_month; $i++) {
                  $weekday = jddayofweek ( cal_to_jd(CAL_GREGORIAN, date("m"), $i, date("Y")), 0);
                  if($weekday == 1){
          				$weeknumber = date("Y")."-".date("m")."-".$i;
          				echo "</tr><tr><td bgcolor=orange>".date("W", strtotime($weeknumber))."</td>";
                          // echo "</tr><tr><td bgcolor=orange>".strftime('%V',strtotime('today'))."</td>";
                  }
                  if($current_day==$i) {
                          echo "<td><b>".$i."</b></td>";
                  }
                  else {
                          echo "<td>".$i."</td>";
                  }
          }
          echo "</tr></table>";
          ?>

            you're more than welcome!

              Write a Reply...