I need a way to find the next XXXday after a given date. In some cases, I will need to chain/increment the results in order to fill an array or table. For example, an array might contain these values:

-The first Tuesday after today
-The first Thursday after that
-The first Tuesday after that
-The first Thursday after that
-The first Saturday after that
-The first Monday after that
-etc.

How can I do this using the API? I've gone over the docs and this issue queue without finding anything similar. Am I blind, or obtuse? HELP!

Thanks. I sure hope this isn't impossible.

Comments

karens’s picture

Status: Active » Fixed
$date = date_make_date($start_date, date_default_timezone_name());
date_modify($date, '+1 Tuesday');
print date_format_date($date, 'medium');
date_modify($date, '+1 Thursday');
print date_format_date($date, 'medium');

That's how to do an erratic pattern. If you had a repeating pattern, you could also use the Date Repeat API, like:

include_once(drupal_get_path('module', 'date_repeat') .'/date_repeat_calc.inc';
$repeats = date_repeat_calc($rrule, $start_date, $end_date, $exceptions);

$rrule is an iCal RRULE, like 'RRULE:FREQ=DAILY;BYDAY=1TU,1TH";
$start_date is a start date for the repeats, in the format YYYY-MM-DD HH:MM:SS.
$end_date is and end date for the repeats, in the same format.
$exceptions is a comma-separated list of dates that are exceptions to the rule. Exceptions are formatted 'YYYY-MM-DD'.

It returns an array of dates that match the rule.

rconstantine’s picture

Thanks so much. Is this: http://www.kanzaki.com/docs/ical/rrule.html the best source of info on RRULES, or is there a better link that you have? You saved my bacon here. Awesome module. Really impressive.

karens’s picture

Yes, that's a good link. I used that to come up with the examples in the test suite.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.