3

I'm Using PHP RRule for Recurrence in my Project. Here Daily and Weekly Recurrence are working fine. I don't know how to use monthly Recurrence in my scenario.

Monthly scenario:

First Sunday of every 2 Months

enter image description here

Code:

$dow=array("SU");
$rrule = new RRule([
    'FREQ' => 'MONTHLY',
    'BYMONTHDAY' => 2,  
    'INTERVAL' => 2,
    'BYDAY' => $dow,    
    'DTSTART' => '2016-12-01',
    'UNTIL' => '2017-12-31'
]); 

foreach ( $rrule as $occurrence ) {
    echo "</br>";
    echo $occurrence->format('D Y-m-d');
}

echo $rrule->humanReadable(),"\n";

//OUTPUT
Sun 2017-04-02
every 2 months on Sunday on the 2nd of the month, starting from 12/1/16, until 12/31/17 
Maria Jeysingh Anbu
  • 3,164
  • 3
  • 34
  • 55

1 Answers1

2

You don't need BYMONTHDAY, you need BYDAY with a number prefix.

In your situation: 'BYDAY' => '1SU' means "the first Sunday". 2SU the second Sunday, -1SU the last Sunday etc.

More information:

Community
  • 1
  • 1
rlanvin
  • 6,057
  • 2
  • 18
  • 24