Last updated 10 January 2011. Created on 10 January 2011.
Edited by iantresman. Log in to edit this page.


This page describes how to show a simple calendar month on your page (node or block), with today's date highlighted (demo). The snippet uses Keith Devens's excellent PHP Calendar script (note the open source license). It does not require the Date module , nor the Calendar module.

I do not claim this method to be approved or secure, and there may be other ways of achieving the same. Readers should check to see if there are any constructive comments below.


To use the PHP Calendar script, you need to make sure that the Node or Block in which you want to use it, has its Input format set to "PHP Code". If this option is not showing, you will need to enable it in your Modules | Core - optional | PHP filter.

Then simply copy the source code for the PHP Calendar script from the section "Download the source" (click the link "plain source code"). I already had text on the Drupal page I wanted the calendar, so I pasted the script at the end (you need to include everything, including the starting <?php tag, and end ?> tag).


To make the calendar month page appear, I simply added the following snippet to my page:

<div class="calright">
<!-- Requires PHP Calendar script, written by Keith Devens -->
<style type="text/css">
div.calright {float:right;margin:0 0 0 20px}
table.calendar caption.calendar-month {font-weight:bold}
table.calendar {background:#eeeeee}
table.calendar th {font-size:12px;width:10px;padding:1px;}
table.calendar td {font-size:12px;width:10px;padding:0px;text-align:center;font-weight:bold}
$time = time();
$today = date('j',$time);
$days = array($today=>array(NULL,NULL,'<span style="color: red; font-weight: bold; font-size: 120%; ">'.$today.'</span>'));
echo generate_calendar(date('Y', $time), date('n', $time), $days);


I have customised it thus:

  • <div class="calright"> puts the entire calendar in its own div, which a bit of CSS then floats to the right hand side of the page
  • <style type="text/css">..</style> adds CSS to style the calendar. I've placed it here so you can style your calendar more quickly. When done, the CSS should be removed to either a stylesheet, or, I can recommend the excellent CSS Injector module.
  • CSS class tags can be seen by either (a) looking at the source code of the HTML page that displays tha calendar, or (b) looking the script source code. Firefox's Firebug is also useful for dynamically inspecting the classes associated with elements on a page, but is somewhat more involved.
  • Other documentation can be found on Keith Devens's PHP Calendar script page.

Looking for support? Visit the forums, or join #drupal-support in IRC.