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
https://forums.phpfreaks.com/topic/40098-weekly-calendar/
Share on other sites

  • 4 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.