FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Brilliance requested - calculating a date next month
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Brilliance requested - calculating a date next month [message #174479 is a reply to message #174450] Mon, 13 June 2011 21:59 Go to previous message
BootNic is currently offline  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*
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Strategic HR Summit 2011 (Jun 25, Mumbai)
Next Topic: MySQL's PASSWORD() function
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 14:03:13 GMT 2024

Total time taken to generate the page: 0.05525 seconds