SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Previous/Next day links

    Hi,

    I have built a calendar which people can view events for the day by clicking through to individual days. I am having difficulty implementing next/previous day links on the day view.

    I was thinking of passing the current date through a next/previous link and then writing a script which checks to see if there is a next or previous day.

    Does anyone know of any php examples of this or at least point me in the right direction.

    Thanks

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    How are you storing the date being viewed at the moment ?

    You could use the strtotime(); function, this allows you to find a next day / previous day date, look at the PHP manual for more info.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure about the code you have but this should help:
    PHP Code:
    echo 'Previous day: '.date('m-d-Y'strtotime('previous day'));
    echo 
    '<br />';
    echo 
    'Today: '.date('m-d-Y');
    echo 
    '<br />';
    echo 
    'Next day: '.date('m-d-Y'strtotime('next day'));
    echo 
    '<br />';
    $previous mktime(000date('m'), date('j')-1date('Y'));
    echo 
    'Previous day: '.date('m-d-Y'$previous);
    echo 
    '<br />';
    $next mktime(000date('m'), date('j')+1date('Y'));
    echo 
    'Next day: '.date('m-d-Y'$next); 
    In the last 2 examples I am using the mktime function and just adding or subtracting a day from the day parameter.

    Hope this helps.
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers

  4. #4
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    How are you storing the date being viewed at the moment ?

    You could use the strtotime(); function, this allows you to find a next day / previous day date, look at the PHP manual for more info.
    I am basically passing it like this ?day=3&month=4&year=2007 in order to view the correct day.

  5. #5
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hiya, this is what I use for my calendar

    previous month
    PHP Code:
    $prevTS strtotime("$year-$month-01 -1 month"); // timestamp of the first of last month 
    $pMax date('t'$prevTS); 
    $pDay = ($day $pMax) ? $pMax $day
    list(
    $y$m$F) = explode('-'date('Y-m-F'$prevTS)); 
    echo 
    "<p>\n"
    echo 
    "<a href=\"?day=$pDay&amp;month=$m&amp;monthName=$F&amp;year=$y\">Previous Month</a>\n"
    next month
    PHP Code:
    $nextTS strtotime("$year-$month-01 +1 month"); 
    $nMax date('t'$nextTS); 
    $nDay = ($day $nMax) ? $nMax $day;
    list(
    $y$m$F) = explode('-'date('Y-m-F'$nextTS)); 
    echo 
    "<a href=\"?day=$nDay&amp;month=$m&amp;monthName=$F&amp;year=$y\">Next Month</a>\n"


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
  •