Re: Brilliance requested - calculating a date next month [message #174479 is a reply to message #174450] |
Mon, 13 June 2011 21:59 |
BootNic
Messages: 10 Registered: November 2010
Karma:
|
Junior Member |
|
|
On Sun, 12 Jun 2011 15:05:48 -0400
bill <nobody(at)spamcop(dot)net> wrote:
> I am quietly banging my head on the wall. In concept it seems so
> simple:
>
> I need to calculate the date of an appointment next month. but:
> it needs to be on the same day of the month, eg: from the 2nd
> Tuesday of this month to the 2nd Tuesday of next month.
would be neat if one could just say 'second tue of june 2011'
strtotime or DateTime
$month = 'june';
$year = 2011;
$a = array('first', 'second', 'third', 'fourth', 'fifth');
$d = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
$when = $a[1];
$day = $d[2];
$date = new DateTime("$year-$month-01");
$month = $date->format('F');
$date->modify("$when $day of $month 2011");
$ThisMonth = $date->format('l F d, Y');
$ThisMonth = (preg_match("/$month \d{2}, $year/", $ThisMonth))?$ThisMonth
:"no $when $day";
print "<div>".$ThisMonth."</div>";
$date->modify("+1 month");
$month = $date->format('F');
$NextMonth = $date->modify("$when $day of $month 2011");
$NextMonth = $NextMonth->format('l F d, Y');
$NextMonth = (preg_match("/$month \d{2}, $year/", $NextMonth))?$NextMonth
:"no $when $day";
print "<div>".$NextMonth."</div>";
[snip]
--
BootNic Mon Jun 13, 2011 05:59 pm
When I was young, I was put in a school for retarded kids for two years before
they realized I actually had a hearing loss...and they called ME slow!
*Kathy Buckley*
|
|
|