export function* dateRange(
start: Date,
end: Date,
stepMs: number = 86_400_000,
): Generator<Date> {
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
Create a free account and build your private vault. Share publicly whenever you want.