SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Changing Dates

  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

    HTML Code:
    				<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>

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Nearly there.

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

    Code:
    <?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...

    Code:
    <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>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is perfect. Thank you so much for leading me in the right direction!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •