#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Next & Previous Days


    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 user clicks on < Previous Day link that they go to Tuesday January 22, 2013 and when they lick on > Next Day they go to Thursday January 24, 2013 etc?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,542
    Rep Power
    595
    This looks like an HTML question.
    Code:
    < <a href="previousday.htm">Previous Day</a> Wednesday January 23, 2013 > <a href="nextday.htm">Next Day</a>
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971
    Originally Posted by gw1500se
    This looks like an HTML question.
    Code:
    < <a href="previousday.htm">Previous Day</a> Wednesday January 23, 2013 > <a href="nextday.htm">Next Day</a>
    Or if you need to figure out how to subtract a day from the current date, you'll need to look into [PHPNET="date"]date()[/PHPNET] functions. These two specifically may help you: [PHPNET="date_sub"]date_sub()[/PHPNET] and [PHPNET="date_add"]date_add()[/PHPNET]
    "Those who can make you believe absurdities can make you commit atrocities."
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    date_sub and date_add are only available in PHP 5.3 and higher. If you don't have those, combine date() with mktime() or strtotime() to get the dates for yesterday and tomorrow.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971
    Good catch, I only skimmed over the manual pages to make sure they were doing what I thought they did.
    "Those who can make you believe absurdities can make you commit atrocities."
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    So I now have this.


    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 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>
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    "Short tags", like you have there, are deprecated.

    PHP Code:
    <a href="?date=<?php echo $previous_date;?>">Previous</a>
    <a href="?date=<?php echo $next_date;?>">Next</a>
    Edit: Also, both your variables are the same.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

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


    Originally Posted by ManiacDan
    "Short tags", like you have there, are deprecated.

    PHP Code:
    <a href="?date=<?php echo $previous_date;?>">Previous</a>
    <a href="?date=<?php echo $next_date;?>">Next</a>
    Edit: Also, both your variables are the same.

    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>;?>
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Both of your variables are now named incorrectly. The first is missing a dollar sign, the second is an object property on a non-existent object.

    Comments on this post

    • pghutch agrees
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Date Format : I want Day Month Date, Year Format


    Originally Posted by ManiacDan
    Both of your variables are now named incorrectly. The first is missing a dollar sign, the second is an object property on a non-existent object.
    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>
  20. #11
  21. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    The first argument to date() (which you're giving as Y-m-d) is the format you want your date to appear in. The other formatting controls are on the manual page for date().

    If you want to use an already-formatted date in date(), you must use strtotime first:

    PHP Code:
    date('c'strtotime($row['date'])); 
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by ManiacDan
    The first argument to date() (which you're giving as Y-m-d) is the format you want your date to appear in. The other formatting controls are on the manual page for date().

    If you want to use an already-formatted date in date(), you must use strtotime first:

    PHP Code:
    date('c'strtotime($row['date'])); 
    Well I need this format so I can pass it through the url
    <?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'));
    ?>


    So can I restate the DATE variable as something else with the proper formatting?
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Here is my full code below where do I add your suggestion?

    date('c', strtotime($row['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'));
    ?>



    <?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>
  26. #14
  27. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    When you use date(), change the first argument. That's the answer. Find date() in your code. First thing in there, the 'Y-m-d', can be ANY combination of format strings listed in the manual.

    Also, your final two lines of code are still wrong.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo