tags:

views:

40

answers:

2

Okay, so I need to use PHP to obtain the date of the next occurrence of the 18th.

For example, let's say I ran my script on Dec. 28th, 2011. I would need some code that would be able to spit out 2012-01-18. If it were April 9th, 2011, I would need the code to spit out 2011-04-18. Make sense?

Any ideas?

+2  A: 

This should give you the next occurrence of the 18th

$nextDay = 18;
$nextDate = (date('d') > $nextDay) ? date('Y-m', strtotime('+1 month')).-'.$nextDay : date('Y-m').'-'.$nextDay;
Ben Rowe
perfect, thanks.
lewisqic
A: 

Too easy, PHP has a LOT of date/time related functions, you should check them out here.

Example:

$year = date('Y');
$month= date('m')+1;
if ($month == '13')
    {
    $month = '01';
    $year = $year+1;
    }
echo $year."-".$month."-18";
Andrew Dunn
This code will output next January 18th any day in December, and the 18th of the current month in any other month.
Wooble
Actually the error was that the year was always incremented, but whatever...
Andrew Dunn