1. Go to this page and download the library: Download benhall14/php-calendar library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
benhall14 / php-calendar example snippets
$calendar = new Calendar;
$calendar->stylesheet();
# 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/docs/#api-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
$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.