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_columnSchema · Garden ShopTable · orders6 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 afterMay 1, 2024. Sort from oldest to newest.
- Columns: order_id, order_date, status.
- Rows: 10 orders.
- The first row should be order 7 from 2024-05-01.
Related
See why text, numbers, dates, and booleans behave differently.
Compare, sort, and calculate with numeric values.
Filter text values with string literals.
Use true/false columns in filters.