PinoyTech.org

CodeIgniter, Kohana, Mootools, jQuery and CSS

Splitting Date ranges Into Single Dates

Posted by teejay on May 12, 2009

Ever wanted to have date ranges in your database table split into single dates. I had this problem when I tried to interface with the CodeIgniter Calendaring class. I needed to split date ranges in a calendar application I was trying to make.

Since my modification to the CodeIgniter Calendaring class needed arrays with this structure:

$data = array(
               3  => array('description'),
               7  => array('description'),
               13 => array('description'),
               26 => array('description')
             );

I needed the dates split into single dates.

Solution

Here's what I did to solve the issue:

     $start_date = strtotime($result->event_start);
     $end_date = strtotime($result->event_end);
     while($start_date <= $end_date)
     {
     // do stuff with $start_date
      $start_date+=86400;
     }

Neat huh?

Categories: How To

Tags: php

No Comments

Comments are not allowed