Working with Calendar in CodeIgniter

Hello Readers,

I would like to write about working with calendars in CodeIgniter. We use dates in many parts of our application. Consider an example where you have to display “Thoughts of the Day” in calendar format. When you click on a date, it takes you to a page where it display a thought. To do this using CodeIgniter is very simple. As I mentioned about libraries and the advantages of using them in my earlier posts, today I would like to explain about “Calendar” library.

Lets see how to use it. In order to use the library we have to first load it. The code to load the library is



And displaying the calendar is pretty simple. Just add the following line

echo $this->calendar->generate();

This two lines will display a calendar of the current year and month. The result will be like the following screenshot.


If you want to display for a specific year and month, lets say 2010 march, we can do that by passing year and month as parameters to the generate method.

echo $this->calendar->generate(2010,3);

If in case, you wish to change the start day to Monday we can do that as well. We can customize it as we want. To make Monday as the first day make the following changes.

$prefs = array (
               'start_day'    => 'monday',
               'month_type'   => 'long',
               'day_type'     => 'short'
$this->load->library('calendar', $prefs);
echo $this->calendar->generate();

If you wish to add next and previous link to the calendar, we can do that by

$prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   => ''
$this->load->library('calendar', $prefs);
echo $this->calendar->generate($this->uri->segment(2), $this->uri->segment(3));

Coming to the important section, linking the dates to separate page, the code is

$data = array(
               3  => '',
               7  => '',
               13 => '',
               26 => ''
echo $this->calendar->generate(date('Y'),date('m'),$data);

The result would look like


Thanks for reading.

Don’t forget to subscribe to Geeks.Gallery, to get free emails to your inbox.

Subscribe to Geeks.Gallery

Follow me


Web Developer at Energy Alternatives India
I'm interested in developing Web applications andkeen on learning new technologies.

View Nagarajan's Profile
Follow me

Latest posts by Nagarajan (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *

займ на карту онлайн круглосуточно