Working with Dates and Times in SQL
Date columns let SQL compare calendar values instead of plain text.
Dates look like text when you read them, but SQL treats date columns as
calendar values. That means sorting by a date puts earlier dates before
later dates, and comparisons like
>=
work chronologically.
In DuckDB, a clear way to write a fixed date is
date '2024-05-01'. Other SQL databases have similar ideas, but the exact syntax can vary.
select id_column, date_column
from table_name
where date_column >= date '2024-05-01'
order by date_column Schema · Garden Shop Table · orders 6 columns · 24 rows
One row per order. Unshipped orders have a null shipped_date.
Show the order id, order date, and status for orders placed on or after May 1, 2024. Sort from oldest to newest.
Run your query to inspect the result.
Expected answer
- Columns: order_id, order_date, status.
- Rows: 10 orders.
- The first row should be order 7 from 2024-05-01.
Related
Date parts, math, and truncation.
Length, case, trimming, slicing, and concatenation.
IS NULL, COALESCE, NULLIF, and null-safe logic.
See why text, numbers, dates, and booleans behave differently.
Compare, sort, and calculate with numeric values.
Filter text values with string literals.