diff --git a/calendar/renderer.php b/calendar/renderer.php
index 50a30901f8f..e9ba82d892d 100644
--- a/calendar/renderer.php
+++ b/calendar/renderer.php
@@ -432,7 +432,29 @@ class core_calendar_renderer extends plugin_renderer_base {
$week = 1;
$dayweek = $startwday;
+ // Create an array of all the week days.
+ $wdays = array(0 => ''. get_string('sunday', 'calendar'). '',
+ 1 => ''. get_string('monday', 'calendar'). '',
+ 2 => ''. get_string('tuesday', 'calendar'). '',
+ 3 => ''. get_string('wednesday', 'calendar'). '',
+ 4 => ''. get_string('thursday', 'calendar'). '',
+ 5 => ''. get_string('friday', 'calendar'). '',
+ 6 => ''. get_string('saturday', 'calendar'). '');
+
+ // Loop only if the day offset is greater than 0.
+ // This loop involves shifting the days around until the desired start day
+ // is at the start of the array.
+ $daycount = 0;
+ while ($display->minwday > $daycount++) {
+ $wdays_end = array_shift($wdays);
+ array_push($wdays, $wdays_end);
+ }
+
+ // Now we set the (modified) array to the table header to be displayed.
+ $table->head = $wdays;
+
$row = new html_table_row(array());
+
// Paddding (the first week may have blank days in the beginning)
for($i = $display->minwday; $i < $startwday; ++$i) {
$cell = new html_table_cell(' ');