Jump to content

Weekly Calendar


christo16

Recommended Posts

Hello Everyone,

I have made a weekly calendar and it works fine until you get to the next year, it won't let you go to the previous week at all.  Heres the link http://syedesign.com/temp/calendar.php, if you click on the link on that page "Click Here for Dec 28th" it will take you to the end of the year and you can see the problem.  I can solve the problem by subtracting 1209600 (2 weeks) instead of 604800(1 week) for previous week but when I get back to the current year it will subtract 2 weeks.  Thank for any help!

Heres a look at my code:

 

<?
//Finds out what week it currently is
if (!$_GET["week"]) {
$week2 = date('W') ; } else {
$week2 = date("W ", $_GET[week]); }

//Finds out what year it is, ***(I think this is where my problem is)***
$iWeekNum = ($week2);
if (!$_GET["week"]) {
$iYear = date("Y");} else {
  $iYear = date("Y", $_GET[week]);}

//This function finds the start day and end day for any given week based on the week number
function WeekToDate ($week, $year)
{
	$Jan1 = mktime (1, 1, 1, 1, 1, $year);
	$iYearFirstWeekNum = (int) strftime("%W",mktime (1, 1, 1, 1, 1, $year));

		if ($iYearFirstWeekNum == 1)
			{
				$week = $week - 1;
			}
	$weekdayJan1 = date ('w', $Jan1);
	$FirstMonday = strtotime(((4-$weekdayJan1)%7-5) . ' days', $Jan1);
	$CurrentMondayTS = strtotime(($week) . ' weeks', $FirstMonday);
return ($CurrentMondayTS);
}

$sStartTS = WeekToDate ($iWeekNum, $iYear);
$sStartDate = date ("F d, Y", $sStartTS);

//Adjusting the first number will change the number of days between
$sEndDate = date ("F d, Y", $sStartTS + (6*24*60*60));

//Converts english time back to unix time
$startofweek = strtotime($sStartDate);
$endofweek = strtotime($sEndDate); 
//print date ("M d, Y", $_GET[week]); 
?>
<p align=center><a href=calendar.php?function=staffing&week=<?print $endofweek-604800;?> >Previous </a><?
print $sStartDate." to ". $sEndDate;?>
<a href=calendar.php?function=staffing&week=<? print $endofweek+604800;?> > Next</a></p>
<? //Declaration of variables
$sat = $startofweek; $sun = $startofweek+86400; $mon = $startofweek+172800; $tues = $startofweek+259200;
$wed = $endofweek-172800; $thur = $endofweek-86400; $fri = $endofweek;?>
<div id="calendar">
<p align=center>
<a href=calendar.php?function=staffing&week=1198828800>Click Here for Dec 28th</a>

Link to comment
Share on other sites

  • 4 months later...
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.