// Created on savesnippets.com ยท https://savesnippets.com/oSte2910KZCFcc export function* dateRange( start: Date, end: Date, stepMs: number = 86_400_000, ): Generator { if (stepMs <= 0) throw new Error('stepMs must be positive'); for (let t = start.getTime(); t <= end.getTime(); t += stepMs) { yield new Date(t); } } for (const d of dateRange(new Date('2025-01-01'), new Date('2025-01-05'))) { console.log(d.toISOString().slice(0, 10)); } // 2025-01-01 // 2025-01-02 // 2025-01-03 // 2025-01-04 // 2025-01-05