Changing Dates

I’m trying to create a table that has 7 columns for current date and the next 6 days after. I want to have it so when you click the arrows it will move the dates to the next week. I’m trying to wrap my mind around the best way to do this. Any recommendations?

				<tr>
				<td>Previous <</td>
				<td><?php echo date("l - F d, Y"); ?></td>
				<td><?php echo date("l - F d, Y", strtotime('+1 day')); ?></td>
				<td><?php echo date("l - F d, Y", strtotime('+2 day')); ?></td>
				<td><?php echo date("l - F d, Y", strtotime('+3 day')); ?></td>
				<td><?php echo date("l - F d, Y", strtotime('+4 day')); ?></td>
				<td><?php echo date("l - F d, Y", strtotime('+5 day')); ?></td>
				<td><?php echo date("l - F d, Y", strtotime('+6 day')); ?></td>
				<td>>> Next</td>
				</tr>

Nearly there. :slight_smile:

As usual, there’s a ton of ways to do this; be here’s an easy (untested) starter for you.


<?php
$start = isset($_GET['start']) ? strtotime($_GET['start']) : time() ;
$prev = strtotime('-7 days', $start);
$next = strtotime('+7 days', $start);
?>
<a href="/?start=<?php echo date('Y-m-d', $prev); ?>">Previous</a>


<?php foreach(range(0, 6) as $diff): ?>
    <p><?php echo date('r', strtotime('+' . $diff . ' days', $start));?></p>
<?php endforeach; ?>


<a href="/?start=<?php echo date('Y-m-d', $next); ?>">Next</a>

Which should give you something like…


<a href="/?start=2012-09-17">Previous</a>


    <p>Mon, 24 Sep 2012 20:45:11 +0100</p>
    <p>Tue, 25 Sep 2012 20:45:11 +0100</p>
    <p>Wed, 26 Sep 2012 20:45:11 +0100</p>
    <p>Thu, 27 Sep 2012 20:45:11 +0100</p>
    <p>Fri, 28 Sep 2012 20:45:11 +0100</p>
    <p>Sat, 29 Sep 2012 20:45:11 +0100</p>
    <p>Sun, 30 Sep 2012 20:45:11 +0100</p>


<a href="/?start=2012-10-01">Next</a>

This is perfect. Thank you so much for leading me in the right direction!