Building a Printable Monthly Planner in PHP

Tutorial Overview

This tutorial demonstrates how to build a dynamic monthly event planner and form generator using PHP. By combining PHP's native DateTimeImmutable object with loops and HTML table structures, you can generate a fully interactive calendar grid where users can input custom events for any day of the month.

Key Features:

  • Dynamic month-to-month navigation with automatic year boundary rollovers.
  • Weekday alignment offset calculation using date('w').
  • Form textareas embedded within daily calendar cells for event entry.

Complete Source Code

You can copy the complete PHP script below and use it on your local server:

<?php
session_start();
$prm = filter_input(INPUT_GET, 'prm', FILTER_VALIDATE_INT);
$chm = filter_input(INPUT_GET, 'chm', FILTER_VALIDATE_INT);
$current_month = $prm ? $prm : (int)date("n");
$current_year = (int)date("Y");

try {
    $date_obj = DateTimeImmutable::createFromFormat('!Y-n-j', "$current_year-$current_month-1");
    if ($chm !== null && $chm !== 0) {
        $date_obj = $date_obj->modify(($chm > 0 ? "+{$chm} month" : "{$chm} month"));
    }
} catch (Exception $e) {
    $date_obj = new DateTimeImmutable('first day of this month');
}

$m = (int)$date_obj->format('n');
$y = (int)$date_obj->format('Y');
$no_of_days = (int)$date_obj->format('t');
$mn = $date_obj->format('M');
$yn = $date_obj->format('Y');
$j = (int)$date_obj->format('w');

$adj = '';
for($k = 1; $k <= $j; $k++){                        
    $adj .="<td>&nbsp;</td>";
}

$body = "<form method='post' action='php_monthly_plannerck.php' name='f1'><input type='hidden' name='prm' value='$m'>";
$body .= "<table border='1' bordercolor='#FFFF00' cellspacing='0' cellpadding='0' align='center' width='90%'><tr><td>";
$body .= "<table cellspacing='0' cellpadding='0' align='center' width='100%' border='1'>
<tr>
<td align='center' bgcolor='#ffff00'><a href='php_monthly_planner.php?prm=$m&chm=-1' rel='nofollow'>&lt;</a></td>
<td colspan='5' align='center' bgcolor='#ffff00'><b>$mn $yn</b></td>
<td align='center' bgcolor='#ffff00'><a href='php_monthly_planner.php?prm=$m&chm=1' rel='nofollow'>&gt;</a></td>
</tr>
<tr>";
$body .= "<td><b>Sun</b></td><td><b>Mon</b></td><td><b>Tue</b></td><td><b>Wed</b></td><td><b>Thu</b></td><td><b>Fri</b></td><td><b>Sat</b></td></tr><tr>";

for($i = 1; $i <= $no_of_days; $i++){
    $body .= $adj . "<td valign='top'>$i<br><textarea name='t[$i]' rows='2' cols='7'></textarea></td>";
    $adj = '';
    $j++;
    if($j == 7){
        $body .= "</tr><tr>"; 
        $j = 0;
    }
}
$body .= "</tr><tr><td colspan='7' align='center'><b>plus2net.com Calendar Generator</b></td></tr>";
$body .= "</table></td></tr></table>";

$body .= "<table border='0' width='50%' cellspacing='0' cellpadding='0' align='center' class='mt-3'><tr>
<td align='center'>Total Width</td><td><input type='text' name='t_width' value='770' size='4'></td>
<td align='center'>Cell Height</td><td><input type='text' name='c_height' value='50' size='4'></td>
</tr>";
$body .= "<tr><td colspan='4' align='center' class='pt-3'>
<input type='submit' value='Display Printer Friendly Page' class='btn btn-primary btn-sm mx-1'/>
<input type='submit' value='Display HTML Code' class='btn btn-secondary btn-sm mx-1'/>
</td></tr></table></form>";

echo $body;

Live Interactive Demonstration

Test the calendar generator below. Enter notes or events into any date cell and generate a printer-friendly layout or clean HTML code structure.

< Dec 2025 >
Sun Mon Tue Wed Thu Fri Sat
 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
plus2net.com Calendar Generator
Total Width Cell Height




Subscribe to our YouTube Channel here



plus2net.com







Anthony Aniah

30-04-2015

Bless you for the codes. Very Good.
Syed Zakir

21-10-2015

Respected sir ....... i want coding of calendar event on type day on month.
Please send me i'm thank full to You.

10-06-2020

Hi, may i ask, for this PHP calendar, is it able to insert "number" to each date, add a new field which auto calculate the total number at bottom, and create a button to save it? Can this calendar insert into every user profile page which every user got their own calendar update?

24-06-2020

Yes, can be done, you need one member table where number against the date along with the member id is stored. While displaying you can read the numbers of the member with calendar date ( of a range or month ) and display them. Sum of these numbers can be displayed by just adding.
These numbers are unique to the members. You can also give them edit facility.




PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer