Date Functions (CURRENT_DATE, EXTRACT, DATE_TRUNC)
Part of the SQL Roadmap
In short
"Sales this month", "orders by weekday", "revenue per year": nearly every business report slices time. Date functions pull dates apart and round them into neat buckets.
Date functions get today's date, pull out parts like year or month, and round dates down to a period. EXTRACT works in both MySQL and PostgreSQL, DATE_TRUNC is PostgreSQL, and MySQL uses DATE_FORMAT or YEAR() and MONTH().

Think of it like this
The wall calendar
Look at a date on the kitchen calendar and you can read its year, month and day separately (EXTRACT). Flip back to the first page of its month and you've rounded it down to the month (DATE_TRUNC). The red circle around today is CURRENT_DATE.
Watch it happen
Pulling apart 2026-08-17 14:35
1/5A timestamp is really a bundle of parts: year, month, day, hour, minute.
The big ideas
What you need to know
Today and now
CURRENT_DATE gives today's date. CURRENT_TIMESTAMP (or NOW()) gives date and time.
EXTRACT pulls one part
EXTRACT(YEAR | MONTH | DAY | DOW | HOUR FROM ts). Works in PostgreSQL and MySQL. In PostgreSQL, DOW 0 is Sunday.
DATE_TRUNC buckets
DATE_TRUNC('month', ts) rounds down to the first of the month. Also 'week', 'quarter' and 'year'. PostgreSQL only.
MySQL equivalents
YEAR(d), MONTH(d) and DATE_FORMAT(d, '%Y-%m-01') for the month bucket. SQL Server uses DATEPART and DATETRUNC.
See it in code
Walk through the code
1-- Monthly revenue for 20262SELECT3 DATE_TRUNC('month', order_date)::date AS month,4 SUM(amount) AS revenue5FROM orders6WHERE EXTRACT(YEAR FROM order_date) = 20267GROUP BY DATE_TRUNC('month', order_date)8ORDER BY month;9 10-- Orders placed today11SELECT order_id, amount12FROM orders13WHERE order_date = CURRENT_DATE;1/5Round each date down to its month. ::date drops the 00:00:00 time part from the output.
PostgreSQL. In MySQL, replace the month line with DATE_FORMAT(order_date, '%Y-%m-01') and GROUP BY that expression.
Save yourself the pain
Common mistakes
Oops
Grouping by EXTRACT(MONTH FROM order_date) across several years.
Do this instead
January 2025 and January 2026 merge into one row. Use DATE_TRUNC('month', ...) to keep years apart.
Oops
Comparing a timestamp column to CURRENT_DATE with = to find today's orders.
Do this instead
A timestamp at 14:35 isn't equal to midnight. Use created_at >= CURRENT_DATE AND created_at < CURRENT_DATE + 1.
Your mission
Slice by time
Quick check
What does DATE_TRUNC('month', TIMESTAMP '2026-08-17 14:35') return?
Go deeper
- 1Count orders per month using DATE_TRUNC('month', order_date) in PostgreSQL or DATE_FORMAT(order_date, '%Y-%m') in MySQL.
- 2Extract the weekday from a date and find which weekday sells most.
- 3Check the difference between DATE, TIMESTAMP and timestamps with a time zone in your database.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.