note 54933 deleted from function.date by aidan

From: Date: Sun, 31 Jul 2005 12:31:33 +0000
Subject: note 54933 deleted from function.date by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-92810@lists.php.net to get a copy of this message
Note Submitter: thomasfauskanger at gmailc dot om ---- Thanks to nikhil at nikhilzkingdom dot com for this calender-function. I have just modified it a little, so those of us who use monday as the first day in the week may use it too(e.g. Norwegians), and I've put the year and month as arguments in the function so you may create a calender for whatever month and year you'd like. //////////////////////////// AGAIN: this is (allmost) a copy from nikhil at nikhilzkingdom dot com's note: <?php function displayCalenderAsTable($year,$month) { // Find the first day of the current month $year = isset($year)? $year: date("Y"); // this year $month = isset($month)? $month: date("n"); // this month $day=1; // start from first of month $ts = mktime(0,0,0,$month,$day,$year); // unix timestamp of the first day of current month $month_caption=date("M $year",$ts); // caption to table print "<table summary=\"Monthly calendar\"> <caption>$month_caption</caption> <tr> <th>Man</th> <th>Tir</th> <th>Ons</th> <th>Tor</th> <th>Fre</th> <th>L&oslash;r</th> <th>S&oslash;n</th> </tr>\n"; // The days have been moved one day forward, so the week now starts with monday $weekday_first_day = date("w",$ts); // which is the weekday of the first day of week 0-Sunday 6-Saturday //////////////////// //////////////////// //////////////////// //This is the only change except changing the table header $weekday_first_day = ($weekday_first_day==0)? 6: $weekday_first_day-1; // Make it norwegian //////////////////// //////////////////// //////////////////// $slot=0; print "<tr>\n"; // First row starts for($i=0;$i<$weekday_first_day;$i++) // Pad the first few rows(slots) { print " <td></td>"; // Empty slots $slot++; } while(checkdate($month,$day,$year) && $date<32) // till there are valid days in current month { if($slot == 7) // if we moved past saturday { $slot = 0; // reset and move back to sunday print "</tr>\n"; // end of this row print "<tr>\n"; // move on to next row } echo " <td>$day</td>"; // print the day $day++; $slot++; } if($slot>0) // have we started off a new last row { while($slot<7) // padding at the end to complete the last row table { print " <td></td>"; // empty slots $slot++; } print "\n</tr>\n"; // close out last row } print '</table>'; //end of table } displayCalenderAsTable(2005,7); //will create calender for july 2005 displayCalenderAsTable(); //will create calender for current year and month ?>

« previous php.notes (#92810) next »