Jump to content

Previous Day & Next Day


pghutch

Recommended Posts

I have a page where the day and date is displayed like this.

 

 

< Previous Day - Wednesday January 23, 2013 > Next Day

 

 

How do I make it so when the userclicks on < Previous Day link that they go to Tusday January 22, 2013 and when they lick on > Next Day they go to Thursday January 24, 2013 etc?

Link to comment
Share on other sites

Well I am pretty new to PHP So any other code will hep me.

 

Ive started with this but how do I add code to the actual

labels here

 

< Previous Day - Wednesday January 23, 2013 > Next Day

 

What code goes on < Previous Day and > Next Day?

 

Heres what I have so far

 

<?php

$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');

$previous_date = date('Y-m-d', strtotime($date .' -1 day'));

$next_date = date('Y-m-d', strtotime($date .' -1 day'));

?>

Link to comment
Share on other sites

So I now have this. But the links don't go to the next or previous day.

 

The links look like this /index.php?date=<?=$next_date;?>.

 

Where they should actually pass a actual date instead of "<?=$next_date;?>."

 

<?php

$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');

$previous_date = date('Y-m-d', strtotime($date .' -1 day'));

$next_date = date('Y-m-d', strtotime($date .' -1 day'));

?>

 

<a href="?date=<?=$previous_date;?>">Previous</a>

<a href="?date=<?=$next_date;?>">Next</a>

Link to comment
Share on other sites

OK here is where I am now. I appreciate all of the help.

But still no dates are passed in the url....its blank, like this.

 

The links look like this..../index.php?date=

 

Heres my code

 

<?php

$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');

$previous_date = date('Y-m-d', strtotime($date .' -1 day'));

$next_date = date('Y-m-d', strtotime($date .' +1 day'));

?>

 

 

 

<a href="index.php?<?php echo date?>=<?php echo $row->$previous_date;?>" > Previous </a>;?> Todays Date <a href="index.php?<?php echo date?>=<?php echo $row->$next_date;?>" > Next </a>;?>

Link to comment
Share on other sites

Well thanks to everyone's help I've gotten the previous and next to work.

But I have one last question.

I want my date formatted like this: Wednesday January 23, 2012

Right now with the code below the date is outputting like this 2013-01-28.

 

How can I output this <span class="datetxt"> <?php echo $_GET['date'];?></span> to this Wednesday January 23, 2012

 

Here is the code.

 

 

<?php echo '<h3 class="home-title">Schedule for Today<span class="date">';?>

 

<a href="index.php?<?php echo date?>=<?php echo $previous_date;?>" > <img src="assets/images/lftarrow.png" width="28" height="12"> </a>

<span class="datetxt"> <?php echo $_GET['date'];?></span>

<a href="index.php?<?php echo date?>=<?php echo $next_date;?>" ><img src="assets/images/rtarrow.png" width="28" height="12"></a> </span></h3>

Link to comment
Share on other sites

I would suggest that instead of passing strings such as "2012-01-05" as the parameter on the URL - just send an offset from the current date (i.e. +5). It will make your code cleaner and validation simpler (which you are not doing now). It also helps in that you don't have to manipulate a lot of strings. Keep data in as simple/agnostic a format as possible until needed.

 

<?php
//Get offset from URL parameter, default is 0
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
//Define display date using current date and the offset
$display_date = date('l F j, Y', strtotime("$offset days"));
//Determine prev/next offsets based on current offset
$prev_off = $offset - 1;
$next_off = $offset + 1;

?>

<h3 class="home-title">
   Schedule for Today
   <span class="date">
       <a href="test.php?offset=<?php echo $prev_off; ?>"><img src="assets/images/lftarrow.png" width="28" height="12"></a>
       <span class="datetxt"><?php echo $display_date;?></span>
       <a href="test.php?offset=<?php echo $next_off; ?>"><img src="assets/images/rtarrow.png" width="28" height="12"></a>
   </span>
</h3> 

Edited by Psycho
Link to comment
Share on other sites

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.