Skip to content
/ Chapter 2 · Data Types Before Deep Querying
Lesson 2.4 · garden_shop
Lesson 2.4

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.

Pattern
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
Table · orders

One row per order. Unshipped orders have a null shipped_date.

6 columns · 24 rows
order_id int customer_id int order_date date shipped_date date status text coupon_code text
Your task

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.