Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UOG Boys Hostel - Mess Attendance Email Template
<script>
function customCalendar(year, month) {
month--;
let d = new Date(year, month);
let firstDay = d.getDay();
let date = 1, dateIter = 1;
var table = "<table>";
table += "<tr><th colspan=14>" + d.toLocaleString('en-us', { month: 'long' }) + " " + d.getFullYear() + "</th></tr>";
table += "<tr>";
table += "<th colspan=2>Mon</th>";
table += "<th colspan=2>Tue</th>";
table += "<th colspan=2>Wed</th>";
table += "<th colspan=2>Thu</th>";
table += "<th colspan=2>Fri</th>";
table += "<th colspan=2>Sat</th>";
table += "<th colspan=2>Sun</th>";
table += "</tr>";
for (let i = 0; i < 6; i++) {
// creates a table row
table += "<tr>";
//creating individual cells, filing them up with data.
date = dateIter;
for (let j = 1; j <= 7; j++) {
if (i === 0 && j < firstDay) {
table += "<td colspan=2></td>";
} else if (date > daysInMonth(month, year)) {
break;
} else {
let d = new Date(year, month, date);
table += "<th colspan=2>" + d.getDate() + "-" + d.toLocaleString('en-us', { month: 'short' }) + "</th>";
date++;
}
}
table += "</tr>";
// creates a table row
table += "<tr>";
//creating individual cells, filing them up with data.
date = dateIter;
for (let j = 1; j <= 7; j++) {
if (i === 0 && j < firstDay) {
table += "<td></td>";
table += "<td></td>";
} else if (date > daysInMonth(month, year)) {
break;
} else {
let currentDate = new Date(year, month, date);
table += "<td>" + "L" + "</td>";
table += "<td>" + "D" + "</td>";
date++;
dateIter++;
}
}
table += "</tr>";
}
return table;
}
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.