Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Function

pd.date_range

pd.date_range creates a fixed-frequency DatetimeIndex from date bounds, a period count, or both. Specify exactly three of start, end, periods, and freq; inclusive controls boundary inclusion.

Since
2.0.0

How it works

Call pd.date_range with any three of start, end, periods, and freq. It produces equally spaced timestamps according to the frequency, constrains them to the requested bounds, and returns them as a DatetimeIndex; inclusive controls boundary inclusion, while tz, normalize, name, and unit refine the result.

Syntax

pandas.date_range(start=None, end=None, periods=None, freq=None, tz=None, normalize=False, name=None, inclusive='both', *, unit=None, **kwargs)

Parameters

NameTypeDescription
startstr or datetime-like, optionalLeft bound for generating dates.
endstr or datetime-like, optionalRight bound for generating dates.
periodsint, optionalNumber of periods to generate.
freqstr, Timedelta, datetime.timedelta, or DateOffset, default 'D'Frequency for the generated timestamps; defaults to calendar daily frequency.
tzstr, tzinfo, or None, optionalTimezone for the returned localized DatetimeIndex.
normalizebool, default FalseNormalize start and end dates to midnight before generating.
namestr, default NoneName assigned to the resulting DatetimeIndex.
inclusive{'both', 'neither', 'left', 'right'}, default 'both'Which endpoints to include: 'both', 'neither', 'left', or 'right'.
unitstr, default NoneResolution of the resulting DatetimeIndex.
**kwargsdictAdditional keyword arguments accepted by the function.

Returns

DatetimeIndex: A DatetimeIndex object of the generated dates.

Key points

  • The function constructs a DatetimeIndex whose timestamps follow a fixed interval.
  • Frequency aliases may include multipliers, such as five-hour intervals.
  • Use tz to produce a localized DatetimeIndex for a named timezone.
  • Set normalize=True when the input boundaries should be converted to midnight first.
  • The generated dates are returned as a DatetimeIndex rather than a plain list.
  • Pass name to assign a name to the returned index.

Common mistakes

  • Provide exactly three of start, end, periods, and freq; omitting too many or supplying all four is invalid.
  • Use inclusive deliberately when endpoints should be excluded or only one boundary should remain.

Example: Generate quarter-end dates

import pandas as pd

quarter_ends = pd.date_range(
    start="2024-01-01",
    end="2024-12-31",
    freq="QE",
    inclusive="both",
)
print(quarter_ends)

Creates a DatetimeIndex containing quarter-end timestamps within the supplied bounds.

When to use it

Create a regular time axis

Build a regular daily, hourly, monthly, or custom-frequency timeline for indexing or resampling.

Construct a fixed-length schedule

Generate a known number of equally spaced timestamps from a starting point.

Generate timezone-aware dates

Create localized timestamps for calculations or display in a particular timezone.

Interview questions

QWhat does pd.date_range return and how is spacing determined?

It returns a DatetimeIndex containing equally spaced time points. The spacing comes from freq, and the result is restricted to the requested start and end boundaries.

Follow-up: How would you generate a fixed number of timestamps instead? Supply periods and freq, using one boundary if needed, while still specifying exactly three of the four core arguments.

QWhich arguments must be specified?

The function requires exactly three of start, end, periods, and freq. periods sets the number of generated dates, while start and end define bounds and freq defines spacing.

Follow-up: What happens if both bounds and periods are supplied? Add freq as the third required core argument; otherwise the call does not satisfy the documented combination rule.

QHow do you control endpoint inclusion and timezone?

inclusive accepts both, neither, left, or right, with both as the default. It determines whether the start and end boundaries are included in the result.

Follow-up: How can the result be timezone-aware? Pass a timezone name or tzinfo through tz, which is documented as controlling localization of the returned DatetimeIndex.

  • pandas.bdate_range
  • pandas.period_range
  • pandas.timedelta_range
  • pandas.DatetimeIndex

Source: pandas.date_range — pandas 3.0.6 documentation. Checked 2026-10-15.