Sql - Comparing and Sorting Dates
Code Life
By Pierre Marsaa
SQL Date Format: YYYY-MM-DD
In SQL, dates are typically stored and displayed in the format YYYY-MM-DD, which follows the ISO 8601 standard:
- YYYY - Four-digit year (e.g., 2023)
- MM - Two-digit month (01-12)
- DD - Two-digit day (01-31)
This format ensures dates are sorted chronologically when ordered alphabetically.
Loading data...
In our Codémon database, the captured_date column stores when each Codémon was captured. As you can see, the dates are in YYYY-MM-DD format, making them easy to compare and sort.
Important point about date format
The tricky part about dates in SQL is that the oldest date is the smallest one (it's the one that happened first in time).
So, when you sort dates in ascending order, the oldest date comes first. For example, '2023-01-01' is earlier than '2023-12-31'.
Verify