Jump to content

Recommended Posts

Hi,

I am working on an events site where I want to list the next seven days, and then show any events occurring on those days underneath. But, I am getting puzzled by the first hurdle as the whole date thing confuses the hell out of me.

 

All I want is a list like this:

 

SAT 05

SUN 06

MON 07

TUE 08

WED 09

THU 10

FRI 11

 

The list would then automatically regenerate itself every day, so that on the next day it would start on SUN 06 and go til SAT 12. Also bear in mind that I will be storing my dates in the format 2011-06-06 21:00:00.

 

I'm pretty sure this can't be too hard to accomplish! Can anyone steer me in the right direction?

 

Thanks!

Russ

Link to comment
https://forums.phpfreaks.com/topic/238727-creating-list-of-next-seven-days/
Share on other sites

I cut and paste this from a script I made way way back when I was in Iraq. Perhaps it will be of use.

 

<table cellspacing=0 cellpadding=0 border=0 class="cheader" width="100%">
		<tr>
			<td width="33%" align="left" style="font-weight: normal;"><a href="calendar.php?month=<?php echo $workingMonth-1;?>"><?php echo date("F", mktime(date("H"), date("i"), date("s"), $workingMonth-1, date("d"), date("Y")));?></a></td>
			<td width="34%" align="center"><?php echo date("F", mktime(date("H"), date("i"), date("s"), $workingMonth, date("d"), date("Y")));?></td>
			<td width="33%" align="right" style="font-weight: normal;"><a href="calendar.php?month=<?php echo $workingMonth+1;?>"><?php echo date("F", mktime(date("H"), date("i"), date("s"), $workingMonth+1, date("d"), date("Y")));?></a></td>
		</tr>
		</table>
		</th></tr>
		<tr><td class="dow">Sun</th><td class="dow">Mon</th><td class="dow">Tues</th><td class="dow">Wed</th><td class="dow">Thurs</th><td class="dow">Fri</th><td class="dow">Sat</th></tr>
		<?php
		$id_link=connect();
		$day=1;
		$days=date("t", mktime(date("H"), date("i"), date("s"), $workingMonth, date("d"), date("Y")));
		$week=date("w", mktime(date("H"), date("i"), date("s"), $workingMonth, 1, date("Y")));
		?><tr><?php
		for ($a=0; $a<7; $a++) {
			if ($a==$week) {
				break;
			}
			?><td class="blank"></td><?php
		}
		for ($x=$day; $x<=$days; $x++) {
			if ($a >= 7) {
				?></tr><tr><?php
				$a=0;
			}
			$dayName=date("l", mktime(date("H"), date("i"), date("s"), $workingMonth, $x, date("Y")));
			$date=date("Ymd", mktime(date("H"), date("i"), date("s"), $workingMonth, $x, date("Y")));
			$cdate=date("Ymd");
			$cstyle="";
			if ($cdate > $date) {
				$cstyle=" class=\"pastDate\"";
			}
			?><td valign="top"<?php echo $cstyle;?>><div class="cell">
			<div style="float: left;"><?php echo $x;?></div>
			<div style="float: right; font-size: 80%;"><a href="addCalendarEvent.php?date=<?php echo $date;?>" class="np">[+]</a></div>
			<br />
			<?php
			$getDate=$date."000000";
			$getEDate=($date+1)."000000";
			$sql="SELECT * FROM calendar WHERE STARTDATE >= {$getDate} AND STARTDATE < {$getEDate} ORDER BY STARTDATE ASC";
			if (@mysql_num_rows($query=@mysql_query($sql)) > 0) {
				while ($req=@mysql_fetch_array($query)) {
					?><a href="addCalendarEvent.php?date=<?php echo $date;?>"><?php echo $req['TITLE'];?></a><br /><?php
				}
			}
			?>
			</div></td><?php
			$a++;

		}
		@mysql_close($id_link);
		?>
		</tr>
		</table>

Hey, thanks for the tips, although I couldn't get any of that code to work. For some reason I was getting Friday as Today when it should obviously be Tuesday!!

 

However, I played around with it and now have this which works exactly how it should:

 

<?php
$date = time();
for($i=0; $i<7; $i++) {
   echo date('D d', strtotime("+$i days", $date)) . "<br />";
}?>

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.