April 12th, 2013, 01:22 AM
How to find the date of the next Saturday and Sunday with PHP
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?
April 12th, 2013, 01:38 AM
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).
April 12th, 2013, 01:53 AM
i think your solution is here... : http://www.webmasterworld.com/forum88/11032.htm
Last edited by requinix; April 12th, 2013 at 02:28 AM.
April 12th, 2013, 10:32 AM
BY Specifying Tamestamp
USE this code below:
$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.
April 12th, 2013, 04:56 PM
I wonder why no one replied just
echo $next_saturday = date('l, dS F',strtotime('next Saturday'));
April 12th, 2013, 06:48 PM