User Rating 0.0
Total Usage 0 times
Category Calendars
Is this tool helpful?

Your feedback helps us improve.

About

A date matrix is a two-dimensional array where each row represents one calendar week and each column maps to a weekday. Generating one correctly requires resolving the offset between the first day of the target month and the configured week start (Monday or Sunday). Errors in this offset produce misaligned grids that cascade across every rendered week. This tool computes the matrix for any month of any year, tagging each cell with a type - current, previous, or next - so padding days from adjacent months are unambiguous. It supports locale-aware weekday headers via Intl.DateTimeFormat and outputs raw JSON identical to the createDateMatrix contract, plus CSV and copyable visual grids.

The underlying calculation determines d0, the weekday index of the first of the month, then walks backward by (d0 s) mod 7 days, where s is 0 for Sunday-start or 1 for Monday-start. It always produces 6 full weeks (42 cells) for layout consistency. Note: the locale parameter only affects weekday header labels, not calendar logic. Pro tip: if you need ISO week numbers, the Monday-start matrix aligns directly with ISO 8601 weeks.

calendar date matrix calendar grid month generator date grid week matrix

Formulas

The matrix start date is computed by finding how many padding days from the previous month are needed before the first of the target month:

offset = (d0 s + 7) mod 7

where d0 is the weekday index of the 1st of the month (0 = Sunday, 6 = Saturday) and s is the start-of-week index (0 for Sunday, 1 for Monday). The grid start date is then:

gridStart = 1st of month offset days

The total grid always contains 6 × 7 = 42 cells. Each cell is classified:

{
"previous" if cell.month < target.month"current" if cell.month = target.month"next" if cell.month > target.month

Weekday headers are generated via Intl.DateTimeFormat(locale, { weekday: weekdayFormat }). The formatter is applied to a reference week starting from a known Monday (e.g., 2024-01-01) and reordered based on firstDay.

Reference Data

Locale CodeLanguageShort MonShort TueShort WedShort ThuShort FriShort SatShort SunTypical First Day
en-USEnglish (US)MonTueWedThuFriSatSunSunday
en-GBEnglish (UK)MonTueWedThuFriSatSunMonday
de-DEGermanMoDiMiDoFrSaSoMonday
fr-FRFrenchlun.mar.mer.jeu.ven.sam.dim.Monday
es-ESSpanishlunmarmiéjueviesábdomMonday
it-ITItalianlunmarmergiovensabdomMonday
pt-BRPortuguese (BR)seg.ter.qua.qui.sex.sáb.dom.Sunday
ja-JPJapaneseSunday
ko-KRKoreanSunday
zh-CNChinese (Simplified)周一周二周三周四周五周六周日Monday
ru-RURussianпнвтсрчтптсбвсMonday
ar-SAArabic (Saudi)الاثنينالثلاثاءالأربعاءالخميسالجمعةالسبتالأحدSunday
hi-INHindiसोममंगलबुधगुरुशुक्रशनिरविSunday
tr-TRTurkishPztSalÇarPerCumCmtPazMonday
pl-PLPolishpon.wt.śr.czw.pt.sob.niedz.Monday
nl-NLDutchmadiwodovrzazoMonday
sv-SESwedishmåntisonstorsfrelörsönMonday
da-DKDanishman.tir.ons.tor.fre.lør.søn.Monday
th-THThaiจ.อ.พ.พฤ.ศ.ส.อา.Sunday
he-ILHebrewיום ב׳יום ג׳יום ד׳יום ה׳יום ו׳שבתיום א׳Sunday

Frequently Asked Questions

Months span between 28 and 31 days. Depending on the weekday offset, a month can require 4, 5, or 6 rows. Using a fixed 6-row grid guarantees uniform layout height, preventing UI reflow when navigating between months. The extra cells are filled with days from the next month, tagged with type "next".
JavaScript's Date.getDay() returns 0 for Sunday through 6 for Saturday. When firstDay is "monday", the start index s = 1. The offset formula (d₀ − s + 7) mod 7 correctly wraps negative differences. For example, if the 1st falls on Sunday (d₀ = 0) with Monday start (s = 1): offset = (0 − 1 + 7) mod 7 = 6, meaning 6 days from the previous month precede the 1st.
No. The locale parameter only changes the language of weekday header labels (e.g., "Mon" vs "lun."). The actual grid start day is controlled exclusively by the firstDay option. If you need locale-correct first-day behavior, consult the reference table and set firstDay accordingly.
The algorithm works with actual Date objects, so December 31 of the previous year flows naturally into the padding cells. For January 2024 with Monday start, the offset calculation yields padding days from December 2023, each correctly tagged as type "previous" with proper Date references.
The weekdayFormat maps directly to the Intl.DateTimeFormat weekday option. "short" typically yields 2-3 character abbreviations (Mon, Tue). "long" produces full names (Monday, Tuesday). The exact output depends on the selected locale. For grid compactness, "short" is recommended.
Yes. The JSON output follows the exact createDateMatrix contract: an object with a weekdays string array and a weeks array of arrays. Each day object contains day (number), date (ISO string in JSON), and type ("previous", "current", or "next"). Parse and iterate with any templating system.