#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,575
    Rep Power
    171

    How to find the date of the next Saturday and Sunday with PHP


    Hello world;

    I have a page that I want it to always show the date for the coming weekend.

    In other words, what is the best way to show the date of the next Saturday and Sunday with PHP Version 5.3.3?

    Thank you.
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    Do a mktime() using whatever times you want along with today's date, but use the day as today's + date("w"). What it gives you will be Saturday. +1 day for Sunday.

    Or strtotime() instead of mktime() to add days which has the advantage of being very easy to do if you want to preserve the current time.

    strtotime() also supports "next day" but you have to test that the current date isn't already Saturday (in which case it'll give you next week's Saturday).
  4. #3
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0
    i think your solution is here... : http://www.webmasterworld.com/forum88/11032.htm
    Last edited by requinix; April 12th, 2013 at 01:28 AM.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    18
    Rep Power
    0

    BY Specifying Tamestamp


    USE this code below:

    <?php

    $tomorrow = mktime(0,0,0,date("m"), date("d")+1, date("Y"));

    print "Tomorrow is " . date("Y/m/d", $tomorrow);

    ?>

    The functions in PHP to go further in future is mktime(). If you do not specify a Timestamp , the current date and time will be used.
  8. #5
  9. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,575
    Rep Power
    171
    I wonder why no one replied just
    PHP Code:
    echo $next_saturday date('l, dS F',strtotime('next Saturday')); 
  10. #6
  11. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    I did.

    Comments on this post

    • ManiacDan agrees

IMN logo majestic logo threadwatch logo seochat tools logo