ChronosChronos

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:

ParameterTypeDefaultDescription
fromDateArgsCurrent date-timeStart date of the range (inclusive).
toDateArgs4 weeks from nowEnd date of the range (inclusive).
spannumber4Number of time units to move forward from current date-time.
unit'year' | 'month' | 'week' | 'day''week'Unit of time for relative ranges.
skipDaysWeekDay[] | Enumerate<7>[][]Weekdays to exclude (e.g. ['Sunday', 'Saturday'] or [0, 6]).
onlyDaysWeekDay[] | 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 JavaScript Date objects representing the dates in the specified range.

Behavior

  • Fixed ranges: Includes all dates between from and to (inclusive).
  • Relative ranges: Generates dates forward from current date.
  • onlyDays takes precedence over skipDays when both are provided.
  • Defaults to a 4-week range when 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 of skipDays.

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)

On this page