New version (v2.0) of calendar.class.php now available!

A new version of my php calendar class is now available for download. This new version adds localization and the ability to mark dates that have passed. The download also now includes an examples directory with 8 demonstrations of using the class in various ways. A basic CSS file is also included with the examples as well.

One thing to note, in the previous version of this class the table columns where marked up with CSS ids. These have been changed to classes to allow multiple calendars to be displayed on the same page without breaking validation (an id can only be assigned once per page!). If you were styling the col tags using ID, you will need to update your CSS to change those rules to class definitions.

Besides that, this new version (v2.0) should be fully backwards compatible with the previous version (v1). As always, leave a comment or email me with questions, suggestions or to request a licensing exemption to use this class in your commercial works. (Remember calendar.class.php is released under Creative Commons Attribution-Share Alike 3.0 License)

Download the new version: calendar.class.php v2.0

Previous discussions for calendar.class.php

2 Comments

  1. keith

    # March 20, 2008 - 2:32 pm

    I am using this script and was very happy with it. Anyway, just want to ask if how to put a next and previous button to move from one month to another.

    thanks for a wonderful script!

  2. Jim Mayes

    # March 21, 2008 - 3:29 pm

    That’s something that would have to occur outside of the class and it would depend a lot on how you are setting things up.

    You’ll need to start by finding the first day of the month for the month you are currently displaying. The class can help out there because it provides the properties year and month on instantiation.

    $example = new Calendar();
    $current_month_start = $example->year . "-" . $example->month . "-01";
    

    Then you can do the date math to get next and previous months from there. I suggest using strtotime() to “-1 month” or “+1 month” as the most reliable way to accomplish that task.

    The calendar class can output a month if given just the year and month values. Take a look at sample #2 in the download for how that works if you haven’t already. Basically you call the output method with something like:

    print($example->output_calendar('2007', '08'));
    

    except instead of hard coding the year and month like I have there, you would use what you calculated the previous and next months to be.

    Like I said, what you want to do is really outside the scope of the calendar class which is just for outputting a 1 month calendar. But hopefully I’ve put you on to the right track.

    Taking a look at my post about creating a year-at-a-time calendar might give you some hints as well.

Leave a Reply