Staaarter

Sort Date Intervals

Sorts a newline-separated list of "YYYY-MM-DD to YYYY-MM-DD" date ranges by ascending start date, with full leap-year-aware validation of every date and each range kept intact. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
datesorting

Overview

Introduction

Project timelines, booking periods, and reporting windows are usually expressed as date ranges, and a list of them is rarely handed over already sorted.

This tool sorts a list of "YYYY-MM-DD to YYYY-MM-DD" date ranges by their start date, keeping each range's two dates paired together.

What Is Sort Date Intervals?

A line-based sorter for date ranges: paste one "start to end" interval per line and get the list back ordered by start date.

The format uses the word "to" as the separator, chosen specifically because a bare hyphen would be ambiguous with the hyphens already inside each YYYY-MM-DD date.

How Sort Date Intervals Works

Each line is matched against "YYYY-MM-DD to YYYY-MM-DD" and both dates are validated against real per-month day counts and the leap-year rule.

Valid intervals are sorted using the start date converted to a single comparable number, and the original line text is written back unchanged in the new order.

When To Use Sort Date Intervals

Use it to order a list of project phases, booking periods, or reporting windows by when each one begins.

It also works as a batch validator, since any malformed or non-existent date in the list is caught before sorting.

Features

Advantages

  • Unambiguous "to"-separated format avoids the hyphen-collision problem of a plain "YYYY-MM-DD-YYYY-MM-DD" range.
  • Full leap-year-aware validation of both dates in every interval.
  • Keeps each range's start and end dates paired together in the output.

Limitations

  • Requires the exact "YYYY-MM-DD to YYYY-MM-DD" format with the literal word "to" between dates.
  • Sorts by start date only, it doesn't detect or merge overlapping ranges.

Examples

Sorting two project date ranges

Input

2026-01-01 to 2026-03-01
2025-06-01 to 2025-07-15

Output

2025-06-01 to 2025-07-15
2026-01-01 to 2026-03-01

The 2025 range starts earlier, so it's listed first.

Best Practices & Notes

Best Practices

  • Use the literal lowercase word "to" with a single space on each side between the two dates.
  • Validate an individual date with Calendar Date Validator first if a line is being rejected and you're not sure why.

Developer Notes

Each line is matched with /^(\d{4}-\d{2}-\d{2}) to (\d{4}-\d{2}-\d{2})$/, and both captured dates are validated with the same day-count table and leap-year formula used by Calendar Date Validator and Calendar Date Sorter before the interval's start date is converted to a year*10000+month*100+day sort key.

Sort Date Intervals Use Cases

  • Ordering project phases or milestones by their start date for a timeline view
  • Sorting booking or reservation periods pulled from a spreadsheet export
  • Arranging fiscal reporting periods chronologically before building a summary

Common Mistakes

  • Using a hyphen instead of " to " between the two dates, which the parser can't unambiguously split.
  • Including a date that doesn't exist, like a February 29th in a non-leap year, which is rejected during validation.

Tips

  • For single dates rather than ranges, use Calendar Date Sorter instead.
  • For time-of-day ranges rather than date ranges, use Time Interval Sorter.

References

Frequently Asked Questions