US Holiday Calendar
Never miss a holiday. This script demonstrates the algorithm required to determine the dates of major US holidays for the current year.
Holidays for
Copy the Script
<script>
function getNthWeekday(year, month, weekday, n) {
var d = new Date(year, month, 1);
var count = 0;
while (d.getMonth() === month) {
if (d.getDay() === weekday) {
count++;
if (count === n) return d;
}
d.setDate(d.getDate() + 1);
}
}
var year = new Date().getFullYear();
var thanksgiving = getNthWeekday(year, 10, 4, 4); // Nov (10), Thursday (4), 4th occurence
document.write("Thanksgiving is on: " + thanksgiving.toDateString());
</script>
Frequently Asked Questions
Fixed holidays (Christmas) are easy. Floating holidays (Thanksgiving, Labor Day) require logic to find the 'Nth Weekday of the Month'.
Yes. You can add your own logic to the array, such as 'The first Monday of October'.
Yes. The JavaScript Date object automatically handles leap years when calculating dates in February.