开发者

using the php date/time classes I'm trying to get certain specific days

I am trying to find the right string to modify a DateTime object. I have a recurring calendar object:

Currently finding 'this date of next month' is easy enough: $start_date->modify('+1 month');

However, I am also looking to find 'this day of next month' and 'this 开发者_开发百科day of next year'.

Couldn't find the relevant strings. Cheers

EDIT:

So for example if we take the 2010-09-21 as the start date:

$start_date = new DateTime(20100921);

Finding the current DATE of the next month (numerical representation) would be:

$start_date->modify('+1 month');

However finding the current DAY of the next month (textual representation) is causing me more troubles.

This date is the third tuesday of this month - next month the third tuesday is the 19th


You could do something like this for the 'same day next month':

<?php

switch(floor(date("d") / 7)) {
  case 0:
    $which = "first";
    break;
  case 1:
    $which = "second";
    break;
  case 2:
    $which = "third";
    break;
  case 3:
    $which = "fourth";
    break;
  case 4:
    $which = "fifth";
    break;
}

echo date("c", strtotime(sprintf("%s %s of +1 month", $which, date("l"))));

I dunno if the same works for 'Same day next year' (fiftysecond thuesday of +1 year), but you could also calculate it if you know which day the year starts with and then use mktime().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜