Forum Moderators: coopster

Message Too Old, No Replies

How to find what date the coming Saturday is?

         

bajingan

8:56 am on Dec 7, 2005 (gmt 0)

10+ Year Member



Hi all,

I'm building a website for local events. One of the categories is called "What's on this Saturday". Is there any easy way I can do to find the date with PHP?

Thanks.

chrisjoha

9:51 am on Dec 7, 2005 (gmt 0)

10+ Year Member



I'm sure there's better ways to do it, but this quick code will work most of the time:

<?php
$today = date('w');
$days = 6 - $today;
$saturday = strtotime("+$days days");
?>

dreamcatcher

12:29 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Similar to chrisjoha, but a little simpler:

As a timestamp:
echo strtotime("next Saturday");

Using the date function:
echo date("Y-m-d", strtotime("next Saturday"));

or:

echo date("j F Y", strtotime("next Saturday"));

etc etc

dc

bajingan

2:02 am on Dec 9, 2005 (gmt 0)

10+ Year Member



Thank you! Yes it works! Actually I changed the string from "next Saturday" to "this Saturday" because "next Saturday" gives a date of 2 Saturdays from today while "this Saturday" gives the incoming one.

Thanks.

dreamcatcher

2:31 am on Dec 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, cool. Strange as next Saturday gives me this Saturday. Must be a server thing.

dc