How to: Figure a specific date of the month based on current day

bacamaro
bacamaro used Ask the Experts™
on
Hello,

I'm trying to figure out how to get a specific date of the following month based on what the current day is.

For instance: today is Saturday April 14 - it's the 2nd Saturday of the month. How would I figure out what the date is for the 2nd Saturday of May. I seem to be running myself is circles trying to figure this out.

Thanks,
Brian
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
George Fendlerprogrammer

Commented:
I think the easiest way would be something like:

<?

$TheDay=date("Y m d", strtotime(date("Y-m-d", strtotime(date("Y-m-d"))) . " +1 month"));

echo ("$TheDay");

?>
Most Valuable Expert 2011
Top Expert 2016

Commented:
Most Valuable Expert 2011
Top Expert 2016
Commented:
See http://www.laprbass.com/RAY_temp_bacamaro.php
Outputs: Sat, 12 May 2012 01:00:00 -0500
<?php // RAY_temp_bacamaro.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

$timestamp = strtotime('May 1, 2012 + 2 Saturdays');
echo date('r', $timestamp);

Open in new window

Note that the term "month" is ambiguous; months can have different numbers of days.  Please post back if you have any questions about it.

best regards, ~Ray
George Fendlerprogrammer

Commented:
Ray's solution is much better and more complete.
Interesting question.

Of course, 'the date of the 3rd Wednesday in August' or 'the date of the 3rd Wednesday of next month' are challenging expressions.

This reminds me of couple of programs I wrote a while ago which returned say, 'the date of the last Wednesday in August' and 'the date of the first Tuesday in October'.

If I can assist, I will.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial