dateQuarter
import { dateQuarter } from 'cx/util'; Copied Returns the calendar quarter (1–4) the given date falls in.
Signature
function dateQuarter(date: Date): number
Examples
dateQuarter(new Date(2024, 0, 15)); // 1 — January
dateQuarter(new Date(2024, 5, 1)); // 2 — June
dateQuarter(new Date(2024, 8, 30)); // 3 — September
dateQuarter(new Date(2024, 11, 31)); // 4 — December
Use Cases
Grouping records by quarter
const byQuarter: Record<number, Sale[]> = {};
for (const sale of sales) {
const q = dateQuarter(sale.date);
if (!byQuarter[q]) byQuarter[q] = [];
byQuarter[q].push(sale);
}
To render quarters for display, see the quarter format.
See Also
- monthStart - Get first day of month
- dayBefore - Get the previous calendar day