Error when using DateInterval

Hello, I have what appears to be a strange problem that I cannot figure out and was hoping some fresh eyes could find it.

I have a form that allows the user to repeat events with values of repeatDay, repeatWeek, repeatMonth. That value is passed to the processing page where a switch caries out adding the information to the database. All except for weekly. It seems strange to me that weekly is right in the middle of daily and monthly and they are working as expected. but I get the following error when trying to use the weekly recurrence.

Fatal error:  Uncaught exception 'Exception' with message 
'DatePeriod::__construct() [<a 
href='dateperiod.--construct'>dateperiod.--construct</a>]: This
 constructor accepts either (DateTime, DateInterval, int) OR (DateTime, 
DateInterval, DateTime) OR (string) as arguments.' 

Here is the snippet causing the error. As I mentioned I’ve been staring at this so long perhaps a fresh set of eyes can see what I cannot.

 if($_POST['eventRepeats']) {
                    switch($_POST['eventRepeats']) {
                        case 'repeatDay':
                            $periodInterval = new DateInterval('P1D');
                        case 'repeatWeek':
                            $periodInterval = new DateInterval('P1W');
                        case 'repeatMonth':
                            $periodInterval = new DateInterval('P1M');

                    $period = new DatePeriod( $firstDate, $periodInterval, $lastDate );
                    foreach($period as $newEvent) {
                        $stmt->bindParam(':eventDate', $newEvent->format('Y-m-d'));
                } else {
                    $stmt->bindParam(':eventDate', $firstDate->format('Y-m-d'));

the lastDate variable is determined by this code

 if($_POST['eventEndDate'] == '' and $_POST['eventRepeats'] != 'never') {
                    $lastDate = new DateTime('dec 31');
                } else if($_POST['eventEndDate'] == '' and $_POST['eventRepeats'] == 'never') {
                    $lastDate = new DateTime('0000-00-00');
                } else {
                    $lastDate = new DateTime($_POST['eventEndDate']);                    

Thank you in advance for your assistance.

The problem was in the placement of a quotation mark in my form that turned the eventEndDate into a string. Thank for those that had a look.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.