Get Dates in Range
Returns an array of Date objects within a specific date range.
getDatesInRange
Returns an array of Date objects within a specific date range.
Import
import { getDatesInRange } from 'chronos-date/utils';Function Signatures
function getDatesInRange(options?: SpanRangeForDate): Date[]Overview
Generates dates between two points in time with:
- Fixed date ranges (
from/to) or relative ranges (span/unit) - Weekday filtering (
skipDays/onlyDays)
Parameters
options (Optional)
Configuration object accepting either fixed or relative range parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
from | DateArgs | Current date-time | Start date of the range (inclusive). |
to | DateArgs | 4 weeks from now | End date of the range (inclusive). |
span | number | 4 | Number of time units to move forward from current date-time. |
unit | 'year' | 'month' | 'week' | 'day' | 'week' | Unit of time for relative ranges. |
skipDays | WeekDay[] | Enumerate<7>[] | [] | Weekdays to exclude (e.g. ['Sunday', 'Saturday'] or [0, 6]). |
onlyDays | WeekDay[] | Enumerate<7>[] | [] | Include these (e.g. ['Monday'] or [1], overrides skipDays). |
interface SpanRangeForDate {
/** Start date of the range (inclusive). Defaults to the current date-time if not provided. */
from?: DateArgs;
/** End date of the range (inclusive). Defaults to 4 weeks from the current date-time if not provided. */
to?: DateArgs;
/**
* An array of weekdays to exclude from the date range.
* - Accepts either weekday names (e.g., `'Saturday'`, `'Sunday'`) or numeric indices (0 for Sunday to 6 for Saturday).
* - Ignored if `onlyDays` is provided.
*/
skipDays?: Array<WeekDay> | Array<Enumerate<7>>;
/**
* An array of weekdays to explicitly include in the date range.
* - Accepts either weekday names (e.g., `'Monday'`, `'Wednesday'`) or numeric indices (0 for Sunday to 6 for Saturday).
* - When provided, this overrides `skipDays` and includes only the specified days.
*/
onlyDays?: Array<WeekDay> | Array<Enumerate<7>>;
}Return Value
Date[]— An array of native JavaScriptDateobjects representing the dates in the specified range.
Behavior
- Fixed ranges: Includes all dates between
fromandto(inclusive). - Relative ranges: Generates dates forward from current date.
onlyDaystakes precedence overskipDayswhen both are provided.- Defaults to a
4-week rangewhen no options are provided.
Examples
playground.ts
Notes
Important
- Weekday names must exactly match:
'Monday','Tuesday', etc. (case-insensitive accepted but TypeScript enforces Capitalized form). - When using
onlyDays, all other days are excluded regardless ofskipDays.
Similar Chronos Methods
Type Definitions
type DateArgs = string | number | Date;
type WeekDay = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
type Enumerate<N extends number> = number;Last updated: Sun, Jul 12, 2026 08:55:52AM (UTC)
