How Dates Are Stored
Year, month, day.
Almost every business question has a date in it. Sales this month. Customers who joined last year. Orders that are late. So it's worth taking a little time to understand how dates work in SQL.

- Sales this month
- Customers from last year
- Late orders
The safe date format
In this database, every date is written the same way. Four digits for the year, then a dash, two digits for the month, a dash, and two digits for the day. This is an international standard, and it has a lovely property. If you sort these dates as plain text, they come out in the right order. That's why so many databases use it.
Compare dates like text
Because of that format, you can compare dates with the signs you already know. Here we find orders on or after Christmas Eve, twenty twenty five, in date order. Notice the date goes in single quotes. Run it. The last orders of the year, from the twenty fourth onwards.
SELECT order_id, order_date, status
FROM orders
WHERE order_date >= '2025-12-24'
ORDER BY order_date
LIMIT 5;โโโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโโ โ order_id โ order_date โ status โ โโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโค โ 1250 โ 2025-12-24 โ delivered โ โ 2567 โ 2025-12-24 โ delivered โ โ 1186 โ 2025-12-25 โ delivered โ โ 1580 โ 2025-12-25 โ delivered โ โ 1900 โ 2025-12-25 โ shipped โ โโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโ
A common mistake
A very common mistake is writing dates in other formats, like thirty one, slash, twelve, slash, twenty twenty five. Those don't sort correctly, and comparisons give wrong answers. If you ever build your own tables, always store dates as year, month, day.
Summary
Dates here are year, month, day, and they compare and sort just like text. Next, pulling out the year or the month.
Key takeaways- YYYY-MM-DD
- Compare with < > BETWEEN
- Dates go in quotes