The duplicate listed in the comments ( Getting all dates for Mondays and Tuesdays for the next year ) has a rather verbose answer. Here is a succinct solution using strtotime
with Relative Formats:
// Initialize our dates to UNIX timestamps
$startDate = strtotime( 'next Tuesday', strtotime($startDate) );
$endDate= strtotime($endDate);
// Output all Tuesdays prior to our end date
while ($startDate < $endDate) {
echo date('n/j/Y', $startDate ). "\n";
// Get next Tuesday relative to last Tuesday
$startDate = strtotime( 'next Tuesday', $startDate );
}
Using today ($startDate
) and 2 months from today ($endDate
) as an example, the above outputs:
4/17/2012
4/24/2012
5/1/2012
5/8/2012
5/15/2012
5/22/2012
5/29/2012
6/5/2012
See it in action.
Note: Ensure you are using a proper date format to receive accurate results.