PHP create calendar current month php - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

create calendar of the current month php


 357

PHP


2

<!DOCTYPE html>
<html>
<head>
<style>
tr:nth-child(even) {background: #ffb3b3}
tr:nth-child(odd) {background: #E2E2E2}
</style>
</head>
<body>

<?php

function my_calendar($month,$year,$dateArray) {

$Today_date = date("d");
$Today_date = ltrim($Today_date, '0');

$DaysofWeek = array('Sun.','Mon.','Tue.','Wed.','Thu.','Fri.','Sat.');

$firstDayOfMonth = mktime(0,0,0,$month,1,$year);

$numberDays = date('t',$firstDayOfMonth);

$Components_Date = getdate($firstDayOfMonth);

$monthName = $Components_Date['month'];

$dayOfWeek = $Components_Date['wday'];

$calendar = "<table class='calendar' style='border: 1px solid grey;'>";
$calendar .= "<caption style='color:red;border: 1px solid grey;background-color:lightblue;'>$monthName $year</caption>";
$calendar .= "<tr>";

foreach($DaysofWeek as $day) {
$calendar .= "<th class='header'>$day</th>";
}

$currentDay = 1;

$calendar .= "</tr><tr>";

if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}

$month = str_pad($month, 2, "0", STR_PAD_LEFT);

while ($currentDay <= $numberDays) {

if ($dayOfWeek == 7) {

$dayOfWeek = 0;
$calendar .= "</tr><tr>";

}

$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);

$date = "$year-$month-$currentDayRel";

if($currentDayRel == $Today_date ){ $calendar .= "<td class='day' id='today_date ' rel='$date'><b style='color:red;'>$currentDay</b></td>"; }

else { $calendar .= "<td class='day' rel='$date'>$currentDay</td>"; }

$currentDay++;
$dayOfWeek++;

}

if ($dayOfWeek != 7) {

$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'> </td>";

}

$calendar .= "</tr>";

$calendar .= "</table>";

return $calendar;

}

?>


<?php

$Components_Date = getdate();

$month = $Components_Date['mon'];
$year = $Components_Date['year'];

echo my_calendar($month,$year,$dateArray);

?>

</body>
</html>


By     Created   
The power of the user (%)
4%



The most helpful PHP solutions

detect browser phpdetect browser phpPHP

Click to see more ...

  3.1K     382

create QR code phpcreate QR code phpPHP

Click to see more ...

  2.1K     273

delete array item phpdelete array item phpPHP

Click to see more ...

  1.7K     227

create relative date phpcreate relative date phpPHP

Click to see more ...

  1.3K     215

detect ie phpdetect ie phpPHP

Click to see more ...

  1K     209

get current url phpget current url phpPHP

Click to see more ...

  608     188

Get real client country using php ?Get real client country using php ?PHP

Click to see more ...

  511     168

get meta tag phpget meta tag phpPHP

Click to see more ...

  429     128

detect speed internet phpdetect speed internet phpPHP

Click to see more ...

  405     106

How can I create an object using php ?How can I create an object using php ?PHP

Click to see more ...

  369     103