Full answer
sql
SELECT min('2026-12-01', '2026-02-15') AS iso_min, min('01/12/2026', '15/02/2026') AS dmy_min;| iso_min | dmy_min |
|---|---|
| 2026-02-15 | 01/12/2026 |
For ISO dates, string order equals date order, so min and max work. The day-first version returns '01/12/2026' (1 December), which is the later date, because '0' sorts before '1'.
SQLite's two-argument min() and max() are scalar functions; PostgreSQL uses LEAST and GREATEST for the same purpose. This is one more reason to store dates only in ISO form: every comparison, sort and min/max then behaves like a date operation without conversion.
sql
SELECT min('2026-12-01', '2026-02-15') AS iso_min, min('01/12/2026', '15/02/2026') AS dmy_min;Checked on SQLite 3.46.1, run twice with identical output.
Key points
- ISO date text sorts in date order
- Scalar min(a, b) compares values in SQLite
- Non-ISO date text breaks the ordering
- PostgreSQL uses LEAST and GREATEST
Common mistakes
- Comparing day-first date strings
- Using MIN(a, b) syntax in PostgreSQL
Follow-ups
- What do LEAST and GREATEST do with NULL?
- How would you convert day-first dates?
Tips
- Point out the format dependency