Calendar script

Hopefully someone can help me. I am using this calendar script and I’m trying to change the first day of the week to Monday, instead of Sunday. Thanks in advance for any help :slight_smile:

[php]<?php
$CurDate = getdate(); //gets the server current date.
if (checkdate($HTTP_GET_VARS[‘month’],1,$HTTP_GET_VARS[‘year’]) == NULL)
{
$YearToShow = $CurDate[‘year’]; // $YearToShow = $CurDate[‘year’];
$MonthToShow = $CurDate[‘mon’]; // $MonthToShow = $CurDate[‘mon’];
}
else
{
if (checkdate($HTTP_GET_VARS[‘month’],1,$HTTP_GET_VARS[‘year’]) == false)
{
$YearToShow = $CurDate[‘year’];
$MonthToShow = $CurDate[‘mon’];
}
else
{
$YearToShow = $HTTP_GET_VARS[‘year’];
$MonthToShow = $HTTP_GET_VARS[‘month’];
if ( ($YearToShow < 1902) || ($YearToShow > 2037) )
{
$YearToShow = $CurDate[‘year’];
$MonthToShow = $CurDate[‘mon’];
}
}
}
// This checks to see if the current day will be displayed. If it is make the background a color.
if ( ($YearToShow == $CurDate[‘year’]) && ($MonthToShow == $CurDate[‘mon’]) ) { $DayToShow = $CurDate[‘mday’]; }
// This checks to see how many days are in the month in question.
$NumberOfDays = date(t,mktime(0,0,0,$MonthToShow+1,0,$YearToShow,-1));
// This section converts the month number to the month name.
$MonthNames = array(1=>‘January’,‘February’,‘March’,‘April’,‘May’,‘June’,‘July’,‘August’,‘September’,‘October’,‘November’,‘December’);
//$Years = array(‘1998’,‘1999’,‘2000’,‘2001’,‘2002’,‘2003’,‘2004’,‘2005’);
$Years = array($YearToShow-5,$YearToShow-4,$YearToShow-3,$YearToShow-2,$YearToShow-1,$YearToShow,$YearToShow+1,$YearToShow+2,$YearToShow+3,$YearToShow+4,$YearToShow+5);
// Sets up the href
if ($MonthToShow == 12)
{
$pmon = ($MonthToShow - 1);
$pyear = ($YearToShow);
$nmon = (1);
$nyear = ($YearToShow + 1);
}
else
{
if ($MonthToShow == 1)
{
$pmon = (12);
$pyear = ($YearToShow - 1);
$nmon = ($MonthToShow + 1);
$nyear = ($YearToShow);
}
else
{
$pmon = ($MonthToShow - 1);
$pyear = ($YearToShow);
$nmon = ($MonthToShow + 1);
$nyear = ($YearToShow);
}
}

echo <<<EOT

EOT; $FirstDayOfWeek = date(l,mktime(0,0,0,$MonthToShow,1,$YearToShow)); // This section ofsets the first day of the month so it matches the day of week. switch ($FirstDayOfWeek) { case 'Monday': $offset = 1; break; case 'Tuesday': $offset = 2; break; case 'Wednesday': $offset = 3; break; case 'Thursday': $offset = 4; break; case 'Friday': $offset = 5; break; case 'Saturday': $offset = 6; break; default: $offset = 0; } // this covers the first few empty days. if ($offset > 0) { print ""; echo str_repeat("",$offset); } // This section is to Allow the first day of the week to be sunday and also. // to make sure that the table prints out right. for ($i=1; $i <= $NumberOfDays; $i++) { $DayOfWeek = date(l,mktime(0,0,0,$MonthToShow,$i,$YearToShow)); if($DayOfWeek == 'Sunday') { print ""; } if ($i != $DayToShow) { print ""; } else { print ""; } if($DayOfWeek == 'Saturday') { print "\n"; } } // This section will fill in the blank spaces. // The first part covers Feb. if ( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) ) { if (42-$NumberOfDays-$offset > 0) { echo str_repeat("\n",42-$NumberOfDays-$offset); } print "\n"; } elseif ( ($NumberOfDays != 28) || ($offset > 0) ) { if (35-$NumberOfDays-$offset > 0) { echo str_repeat("\n",35-$NumberOfDays-$offset); print "\n"; } } echo <<<EOT
$MonthNames[$MonthToShow] $YearToShow
<a href=$PHP_SELF?month=$pmon&year=$pyear>&lt;&lt; previous</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href=$PHP_SELF?month=$nmon&year=$nyear>next &gt;&gt;</a>
 
</td>
<td align="right" width="50%"><form action="$PHP_SELF" method="get">

Month
EOT;
while (list($key,$value) = each($MonthNames))
{
if ($key != $MonthToShow) { print ‘’.$value."\n"; }
else { print ‘’.$value."\n"; }
}
print “\nYear<select name=“year”>\n”;
while (list($key,$value) = each($Years))
{
if ($value != $YearToShow) { print ‘’.$value."\n"; }
else { print ‘’.$value."\n"; }
}
echo <<<EOT

Sunday Monday Tuesday Wednesday Thursday Friday Saturday
 
$i$i
  
EOT; ?>[/php]

A few changes for you to make.

Change these two lines:
[php]if($DayOfWeek == ‘Sunday’) {

if($DayOfWeek == ‘Saturday’) {[/php]
to this
[php]if($DayOfWeek == ‘Monday’) {

if($DayOfWeek == ‘Sunday’) {[/php]

Take this line from the top:

[code]

Sunday Monday ...[/code] and put it at the bottom: [code]... Saturday Sunday[/code]

Change this switch around:
from this:
[php]switch ($FirstDayOfWeek) {
case ‘Monday’:
$offset = 1;
break;
case ‘Tuesday’:
$offset = 2;
break;
case ‘Wednesday’:
$offset = 3;
break;
case ‘Thursday’:
$offset = 4;
break;
case ‘Friday’:
$offset = 5;
break;
case ‘Saturday’:
$offset = 6;
break;
default:
$offset = 0;
}[/php]
to this:
[php]switch ($FirstDayOfWeek) {
case ‘Monday’:
$offset = 0;
break;
case ‘Tuesday’:
$offset = 1;
break;
case ‘Wednesday’:
$offset = 2;
break;
case ‘Thursday’:
$offset = 3;
break;
case ‘Friday’:
$offset = 4;
break;
case ‘Saturday’:
$offset = 5;
break;
case ‘Sunday’:
$offset = 6;
break;
default:
$offset = 0;
}[/php]

Hope that helps,
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service