Yearly calendar

Generate a full-year calendar

Loop over the twelve months and calculate each month independently.

$year = 2027;
for ($month = 1; $month <= 12; $month++) {
    $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    echo $month . ': ' . $days . "<br>";
}
2016 Year Calendar
First learn how to display calendar for any month. By modifying this script we will display a yearly calendar showing all 12 months.
Here we will not read the month from query string. We will use one for loop to take the variable value from 1 to 12.
for ($m = 1; $m <= 12; $m++) {
    $dateObject = DateTimeImmutable::createFromFormat('!m', (string) $m);
    $monthName = $dateObject->format('F'); // Month name
}
This value will use as Month and display the calendar by using the month value.
The year can be set to any valid value. The example below uses 2027; change the value to generate another year.
$year=2027; // change this to another year
Now we are reading month value from for loop and year directly so in this script we have removed the dropdown selection box for month and year.

Adding a table

Now we will keep one main table (outer table ) to contain all the calendars. We will set another variable $row. The value of $row will increment by 1 on each loop. Once the value reaches 3 then we will introduce one row.
if(($row % 3)== 0){
echo "</tr><tr>";
}
In the above code we check the modulus of value of $month % 3 and if it is equal to zero then it will add one row. You can change this value ( from 3 ) to any other value to display that many calendars in a row.
This way we can add one row in outer table after displaying three calendars.

This script is included in Zip file.

Changing the stating day of the week

We can start the week from Monday and accordingly the calendar can be changed. The modification required for the same is explained in basic tutorial for monthly calendar. The modified script year-calendar3.php to show yearly calendar with Monday as starting weekday is included in your zip file .
Download plus2net Calendar Script.


Subscribe to our YouTube Channel here



plus2net.com







paul

20-12-2014

how can i make the week start on a
Monday?
smo

21-12-2014

Two lines are to be added and the Header row is to be changed. This part is added to main calendar tutorial showing monthly calendar now. Inside your zip file one new calendar ( cal3.php ) is added which shows week starting from Mondays.




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