PHP Calendar

Open Source Code Projects

A PHP class that makes generating calendars as easy as possible. You can use the addEvent() or addEvents() methods to mark events on the generated calendar.

This is fully compatible from PHP 5.3+, including PHP 8.

You can view this project on Ben's GitHub account: https://github.com/benhall14/php-calendar

Language: PHP
February 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
Event in 7 days
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

PHP Calendar

A PHP class that makes generating calendars as easy as possible.

You can use the addEvent() or addEvents() methods to mark events on the generated calendar.

This is fully compatible with PHP 5 through to PHP 8.1+

Installation via Composer

You can now install this class via composer.

$ composer require benhall14/php-calendar

Remember to add the composer autoloader before using the class and use the correct namespace.

require 'vendor/autoload.php';

use benhall14\phpCalendar\Calendar as Calendar;

Usage

Please make sure you have added the required classes.

Styling

You can apply styles in one of three ways:

  1. Using $calendar->stylesheet() after you have initialised a calendar;

    $calendar = new Calendar;
    $calendar->stylesheet();

  1. Using the calendar.css (or calendar.min.css) from the css directory;

    <link rel="stylesheet" type="text/css" href="css/calendar.min.css">

  1. Create your own stylesheet and add it to the head of your HTML document.

Migration

With the release of 2.0, there were some breaking changes. This includes how dates are passed to the draw method, and the translations.

The display() method no longer works like this:


$calendar->display(array(date('Y-m-d')));

Instead, it now expects an associative array, like:


$calendar->display(['startDate' => '2025-05-01']);

See "Translated Calendars" for more information on how calendars are now translated.

Draw a 'Month View' calendar

In its simplest form, use the following to create a calendar for current month. This will use all defaults (English, Week starting on Sunday, including stylesheet, printing to the page).


    (new Calendar)->display();

Or, you can break it down with full customisability:


    # create the calendar object
    $calendar = new Calendar;
    
    # change the weekly start date to "Monday"
    $calendar->useMondayStartingDate();
    
    # or revert to the default "Sunday"
    $calendar->useSundayStartingDate();
    
    # (optional) - if you want to use full day names instead of initials (ie, Sunday instead of S), apply the following:
    $calendar->useFullDayNames();
    
    # to revert to initials, use:
    $calendar->useInitialDayNames();

    # use the French locale, with days and month names being translated to French.
    $calendar->setLocale('fr_FR');
    # This uses the Carbon locales - https://carbon.nesbot.com/guide/getting-started/localization.html#localization

    # add your own table class(es)
    $calendar->addTableClasses('class-1 class-2 class-3');
    # or using an array of classes.
    $calendar->addTableClasses(['class-1', 'class-2', 'class-3']);
    
    # (optional) - if you want to hide certain weekdays from the calendar, for example a calendar without weekends, you can use the following methods:
    $calendar->hideSaturdays();		# This will hide Saturdays
    $calendar->hideSundays(); 		# This will hide Sundays
    $calendar->hideMondays(); 		# This will hide Mondays
    $calendar->hideTuesdays(); 		# This will hide Tuesdays
    $calendar->hideWednesdays();	# This will hide Wednesdays
    $calendar->hideThursdays();		# This will hide Thursdays
    $calendar->hideFridays();		# This will hide Fridays
    
    # custom data attributes - you can add custom data attributes to days using the following:
    $calendar->addDataAttribute('2025-01-14', 'data-attribute-1', 'value-1');

    # or for multiple attributes
    $calendar->addDataAttributes('2025-01-14', ['data-attribute-1' => 'value', 'data-attribute-2' => 'value-2']);

    # options for draw method
    $options = [
        'color' => 'blue', # One of the predefined colour schemes.
        'startDate' => date('Y-m-d'), # the start date of the calendar.
        'timeInterval' => 10, # the interval between the times - only applicable on the week view calendar.
        'startTime' => '09:00', # the starting time for the week view calendar. For a 9-5 calendar, use 09:00
        'endTime' => '17:00', # the end time for the weekview calendar. For a 9-5 calendar, use 17:00
    ];
    $calendar->draw($options);
    
    # if needed, add event
	$calendar->addEvent(
	    '2022-01-14',   # start date in either Y-m-d or Y-m-d H:i if you want to add a time.
	    '2022-01-14',   # end date in either Y-m-d or Y-m-d H:i if you want to add a time.
	    'My Birthday',  # event name text
	    true,           # should the date be masked - boolean default true
	    ['myclass', 'abc'],   # (optional) additional classes in either string or array format to be included on the event days
	    ['event-class', 'abc']   # (optional) additional classes in either string or array format to be included on the event summary box
	);

    # or for multiple events

	$events = array();

	$events[] = array(
		'start' => '2022-01-14',
		'end' => '2022-01-14',
		'summary' => 'My Birthday',
		'mask' => true,
		'classes' => ['myclass', 'abc'],
        'event_box_classes' => ['event-box-1']
	);

	$events[] = array(
		'start' => '2022-12-25',
		'end' => '2022-12-25',
		'summary' => 'Christmas',
		'mask' => true
	);

	$calendar->addEvents($events);

    # finally, to draw a calendar    
    echo $calendar->draw(date('Y-m-d')); # draw this months calendar    

    # this can be repeated as many times as needed with different dates passed, such as:    
    echo $calendar->draw(date('Y-01-01')); # draw a calendar for January this year    
    echo $calendar->draw(date('Y-02-01')); # draw a calendar for February this year    
    echo $calendar->draw(date('Y-03-01')); # draw a calendar for March this year    
    echo $calendar->draw(date('Y-04-01')); # draw a calendar for April this year    
    echo $calendar->draw(date('Y-05-01')); # draw a calendar for May this year    
    echo $calendar->draw(date('Y-06-01')); # draw a calendar for June this year    
    
    # to use the pre-made color schemes, call the ->stylesheet() method and then pass the color choice to the draw method, such as:    
    echo $calendar->draw(date('Y-m-d'));            # print a (default) turquoise calendar    
    echo $calendar->draw(date('Y-m-d'), 'purple');  # print a purple calendar    
    echo $calendar->draw(date('Y-m-d'), 'pink');    # print a pink calendar    
    echo $calendar->draw(date('Y-m-d'), 'orange');  # print a orange calendar    
    echo $calendar->draw(date('Y-m-d'), 'yellow');  # print a yellow calendar    
    echo $calendar->draw(date('Y-m-d'), 'green');   # print a green calendar    
    echo $calendar->draw(date('Y-m-d'), 'grey');    # print a grey calendar    
    echo $calendar->draw(date('Y-m-d'), 'blue');    # print a blue calendar  
    
    # you can also call ->display(), which handles the echo'ing and adding the stylesheet.
    echo $calendar->display(['date' => date('Y-m-d')]); # draw this months calendar    

Draw a 'Week View' calendar

Instead of a 'month view' calendar, you can now render as a 'week view'. To do this, simply use ->useWeekView(). Remember, when adding events to a week-view calendar, you need to include the time too (see events above).


    $events = array();

    $events[] = array(
        'start' => '2022-01-14 14:40',
        'end' => '2022-01-14 15:10',
        'summary' => 'My Birthday',
        'mask' => true,
        'classes' => ['myclass', 'abc']
    );

    $events[] = array(
        'start' => '2022-11-04 14:00',
        'end' => '2022-11-04 18:30',
        'summary' => 'Event 1',
        'mask' => true
    );
    $events[] = array(
        'start' => '2022-11-04 14:00',
        'end' => '2022-11-04 18:30',
        'summary' => 'Event 2',
        'mask' => true
    );

    $calendar = new Calendar;

    $calendar->addEvents($events)->setTimeFormat('00:00', '00:00', 10)->useWeekView()->display(['startDate' => date('Y-m-d'), 'color' => 'green']);

You can change the start/end times of the day, along with the time interval by using the ->setTimeFormat method:


    $calendar->setTimeFormat('09:00', '17:00', 10)->useWeekView()->display(['startDate' => date('Y-m-d'), 'green']);
    # This will print a week view calendar with 10 minute slots from 9AM to 5PM - ie. 08:00, 08:10, 08:20 and so on.

Monday Start Date

You can now change the weekly start date from a Sunday to a Monday. To activate this, simple use the useMondayStartingDate() method before you 'draw'.


    $calendar = new Calendar;
    $calendar->useMondayStartingDate();
    $calendar->display(['startDate' => date('Y-m-d'), 'color' => 'green']);

Translated Calendars

We now use automatically from the date and the setLocale() method. If you use ->setLocale('fr_FR'), then the days and month names will be French. For more information on the Carbon localization, see https://carbon.nesbot.com/guide/getting-started/localization.html#localization

Credits

Requirements

Carbon

License

Copyright (c) 2016-2022 Benjamin Hall, ben@conobe.co.uk https://conobe.co.uk

Licensed under the MIT license

Donate?

If you find this project helpful or useful in any way, please consider getting me a cup of coffee - It's really appreciated :)

Donate

February 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
March 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
April 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
May 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
June 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
July 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
August 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
September 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
October 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
November 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
December 2026
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
January 2027
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Ben is just great to work with. Efficient, clearly communicating, understanding very quickly, and also giving great advice. I will continue working with Ben on any other WordPress stuff. Sorry for all those other PPH'ers :-)
Bruno V.
Our new helpdesk portal has completely transformed our customer support workflow. Ben built a streamlined system that allows clients to submit tickets, track progress in real-time, and access a self-service knowledge base. This has significantly reduced our 'time-to-resolution' and cut down on repetitive email chains. It’s professional, scalable, and exactly what we needed to level up our service.
Nathaniel R.
Excellent working with Ben. he went above and beyond to help us out and was super responsive. Would highly recommend him!
Joe W
Ben is an amazing developer. He took the project and delivered it on time and within budget, whilst maintaining excellent communication. He also worked beyond what was asked to make sure the project was functioning correctly. Would highly recommend A++++!
David B.
Benjamin is one of the best people that I have worked. Quick, serious and to the point. Highly recommended.
Joseph G
Benjamin, is brilliant at what he does, he really knows what he is at. Gives real useful advice and guidance. He is fast and timely provides updates and always provides solutions and listens well. Trust me Benjamin is a breath of fresh air.
Alexander T.
EXCELLENT AS ALWAYS! I've been working with Ben for a long time now and he is the best programmer. Always efficient and excellent work. Thank you Ben!
Lauren D
We approached Ben to build a bespoke local intranet HR portal with a complex set of requirements—from leave management and holiday requests to internal job boards and even a uniform request system. Not only did he deliver on every front, including in-app messaging and training modules, but he also went above and beyond our original scope. The system has completely transformed how we handle onboarding and benefits.
Dominic S.
Great communication and quick to solve / answer any issues that came up across the way. Would recommend to everyone.
Charlotte C
Ben successfully integrated a booking portal into our WordPress site, allowing us to take direct bookings for the first time. Since the launch, we’ve seen a boost in leads and a much lighter workload for our front-desk staff. Seamless execution!
Christopher P.
Extraordinairly creative, timely and skillful work - Ben is always great to work with.
Charlie D
Fantastic work on our JS script. Ben worked beyond the goals of the project and overcame extra issues that were not defined in the project. He is very quick to respond and patent when waiting for our response. One of our top 5 Developers, We had to deal with many Interfaces including server firewalls/Java-scripting/JSON/PHP/PHP APIs/Remote Databases and automation.
Kevin J.
I was impressed: a freelancer who could give me inputs and details on how he'd implement the solution, kept me updated in the meanwhile, understood my requirements and proposed pretty nice tweaks to make things even better. Ben, you are amazing. I will need no more time to find any other dev's, and will surely deal with you again if I need something related to these things in the future. Full stop.
Marco F.
Ben is an amazing developer with an amazing work ethic. Could not recommend enough.
David C
As a self-employed tutor, I needed a way to streamline student assessments. Ben built a custom app that allows my students to complete quizzes and mock exams directly through my website. The automated notification system is a game-changer! It has made my workflow so much more efficient and has been a huge hit with my students. Ben’s work is top-tier.
Harrison K.
Ben truly went above and beyond. He's fantastic at communication, coding, getting round problems, fixing issues, WordPress, custom plugins and much more. I will be using Ben again for other projects.
Rachael R.
Ben developed a Project Management portal that has become the central hub for our entire team. It has made collaboration effortless—everyone knows exactly what they are responsible for and when it's due. The notification system and progress dashboards keep us all accountable without the need for constant status meetings. Ben didn't just build an app; he built a better way for us to work together.
Benjamin F.
Benjamin is a talented developer who can tackle technically challenging projects with great service and communication. Thoroughly recommended.
Steven M.
Ben had a great idea for my project and completed the project to our requirements very quickly. He also helped me tweak a few issues and answered my questions quickly. We'll work with Ben again!
Gordon S.
Ben built us a fantastic estate agent brochure site that is both beautiful and functional. He integrated a seamless property search feature and intuitive inquiry forms that have significantly increased our lead volume. The backend is easy for us to update with new listings, and the site's speed is impressive. Ben really understands the balance between aesthetic appeal and conversion-driven design.
Sebastian J.
Absolutely superb, a great work ethic, outstanding knowledge and a great eye for detail. I thoroughly recommend him!
Gary J.
Absolutely amazing experience. Ben is an expert in this field, I was amazed at how quickly he jumped on our platform and decoded the code, db etc. He will go over and above to find solutions for clients. Highly recommended.
Harrus A.
Ben went the extra mile and not only resolved the problem but provided a more suitable solution for the long term. Cheers!
William R.
Ben did an amazing job building an animation for us and a wordpress plugin. Thank you so much for e fast service and great comms Ben!
Effie M
Ben was instrumental in launching my online pottery shop. He built a custom solution that handles unique orders and custom-made items with ease. My online presence has never been stronger, and the ability to manage sales through my own website has been a game-changer for my business growth. Highly recommend his services!
Julian D.

Contact

Get in touch

We are always happy to discuss your project and explore how we can assist you. Please reach out to us using the form.

We would love to hear more about your exciting new venture.

Simply fill in the form to get started, and we'll be in touch soon.

Want to email us direct? No problem - ben@conobe.co.uk.