yt-dlp/yt-dlp · error · ValueError

Date range: "{self}" , the start date must be before the end

Error message

Date range: "{self}" , the start date must be before the end date

What it means

Error "Date range: "{self}" , the start date must be before the end date" thrown in yt-dlp/yt-dlp.

Source

Thrown at yt_dlp/utils/_utils.py:1434

    else:
        return date_str


class DateRange:
    """Represents a time interval between two dates"""

    def __init__(self, start=None, end=None):
        """start and end must be strings in the format accepted by date"""
        if start is not None:
            self.start = date_from_str(start, strict=True)
        else:
            self.start = dt.datetime.min.date()
        if end is not None:
            self.end = date_from_str(end, strict=True)
        else:
            self.end = dt.datetime.max.date()
        if self.start > self.end:
            raise ValueError(f'Date range: "{self}" , the start date must be before the end date')

    @classmethod
    def day(cls, day):
        """Returns a range that only contains the given day"""
        return cls(day, day)

    def __contains__(self, date):
        """Check if the date is in the range"""
        if not isinstance(date, dt.date):
            date = date_from_str(date)
        return self.start <= date <= self.end

    def __repr__(self):
        return f'{__name__}.{type(self).__name__}({self.start.isoformat()!r}, {self.end.isoformat()!r})'

    def __str__(self):
        return f'{self.start} to {self.end}'

View on GitHub (pinned to 81ecd58b13)

Solutions

  1. Swap the start and end dates so the start is earlier than the end, e.g. --dateafter 20240101 --datebefore 20240201.
  2. Check relative date expressions ('today', 'now-3days') that may evaluate in an unexpected order.

Example fix

Validate range ordering on construction: if self.start > self.end: raise ValueError(f'Date range: "{self}" , the start date must be before the end date')

When it happens

Trigger: Thrown at yt_dlp/utils/_utils.py:1434 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of yt-dlp/yt-dlp@81ecd58b13 (2026-08-22). Data as JSON: /api/errors/5fb31ec0e0acb736. Report an issue: GitHub.