Jump to content

Change What Day The Week Starts On


Call-911

Recommended Posts

Hello All,

 

I have read through this script a million times, and I can not for the life of me figure out how the script decides which day of the week to start on. Right now the week starts on Monday (which goes against every other calendar we use). I need to figure out how to make the week start on Sunday.

 

Here's the script:

<style type='text/css'>
.outofrange
{
background-color: #d9cdb3;
}
.currentday
{
background-color: #ccc;
}		
</style>

<?PHP
$Year = preg_replace("/[^0-9]/","",$_GET['year']);
$Month = preg_replace("/[^0-9]/","",$_GET['month']);

if ($Month == "") { $Month = date("n"); }
if ($Year == "") { $Year = date("Y"); }
if ($Month==0)  { $Month=12; $Year--; }
if ($Month==13) { $Month=1;  $Year++; }

$myServer = "xxxxxx";
$myUser = "xxxxxx";
$myPass = "xxxxxx";
$myDB = "Calendar"; 

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB"); 

//declare the SQL statement that will query the database
$query = "
SELECT *
FROM calendar
WHERE school = '00'
";

//execute the SQL query and return records
$result = mssql_query($query);

//display the results 


while($row = mssql_fetch_array($result))
{
if (date("Y",strtotime($row['date']))==$Year)
	{
	$Event[date("z",strtotime($row['date'])+1)+1] .= $row['event'] . "<br />" . "<font color='#" . $row['colors'] . "'>" .  $row['location']  . "</font>" . "<p>";
	}
}


$Timestamp = strtotime("$Year-$Month-01");

for ($Day=1;$Day<=32;$Day++)
{
if (checkdate($Month,$Day,$Year))
	{
	$LastDayInMonth = $Day;
	}
}

$FirstDayInMonth = date("N",$Timestamp);	

for ($MakeCal=$FirstDayInMonth;$MakeCal<=$FirstDayInMonth+$LastDayInMonth;$MakeCal++)
{
//echo "$MakeCal<br />";
}
$WeeksNeeded = ceil(($FirstDayInMonth+$LastDayInMonth)/7);

echo "<div align='center'><span class='bodyb'>" . date("F Y",$Timestamp) . "</span></div><p>";

echo "<table width='100%' border='0'> 
	<tr>
		<td align='left' valign='top'><a href='index.php?month=" . (($Month)-1) . "&year=$Year' class='monthview'>Previous Month</a></td>
		<td align='right' valign='top'><a href='index.php?month=" . (($Month)+1) . "&year=$Year' class='monthview'>Next Month</a></span></td>
	</tr>
	</table>";
echo "<p>";

//Main Table starting with days of week through the month views//

echo "<table width='615px' cellspacing='0' cellpadding='2' border='1' bordercolor='#666666'>
<tr>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
";

for ($DoWeeks=1;$DoWeeks<=$WeeksNeeded;$DoWeeks++)
{
for ($DoDays=1;$DoDays<=7;$DoDays++)
	{
	$CurrentDay++;
	if ($CurrentDay < $FirstDayInMonth)
		{
		echo "<td width='10%' class='outofrange'> </td>";
		}
	else
		{
		if (($CurrentDay-$FirstDayInMonth)+1>$LastDayInMonth)
			{
			echo "<td width='10%' class='outofrange'> </td>";
			}
		else
			{
			$DayOfYear = date("z",strtotime("$Year-$Month-" . (($CurrentDay-$FirstDayInMonth)+1))) + 1;
			if ($DayOfYear==date("z")+1 && date("Y")==$Year)
				{
				echo "<td width='10%' height='100' valign='top' class='currentday'><strong>" . (($CurrentDay-$FirstDayInMonth)+1) . "</strong><br />";
				}
			else
				{
				echo "<td width='10%' height='100' valign='top'><strong>" . (($CurrentDay-$FirstDayInMonth)+1) . "</strong><br />";
				}

			if ($Event[$DayOfYear]!="")
				{
				echo $Event[$DayOfYear] . $Location[$DayOfYear] . "<p /></font>";
				}
			echo "</td>";
			}
		}
	}
echo "</tr><tr>";
}
echo "</table><p>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.