MySQL DATE() Function
MySQL DATE(): Extract the Calendar Date From a Timestamp
The DATE() function extracts the 'YYYY-MM-DD' date part from a DATE, DATETIME, or valid date-time string expression. It discards hours, minutes, seconds, and microseconds cleanly.
Reporting queries rely on DATE() to group timestamped transactions by calendar day and display clean dates without clock clutter.
Syntax
Pass a single date or datetime expression to DATE():
DATE(expr)
expr: ADATE,DATETIME,TIMESTAMP, or string formatted like'2026-05-12 14:30:00'.
The function returns a DATE value, or NULL if the input cannot be parsed as a valid calendar date.
Practical Example
Suppose your analytics team aggregates daily revenue from demo_orders, where created_at stores full DATETIME timestamps.
SELECT
DATE(created_at) AS order_day,
COUNT(*) AS total_orders,
SUM(total_amount) AS daily_revenue
FROM demo_orders
GROUP BY DATE(created_at)
ORDER BY order_day;
| order_day | total_orders | daily_revenue |
|---|---|---|
| 2026-05-10 | 4 | 620.00 |
| 2026-05-11 | 7 | 1145.50 |
| 2026-05-12 | 3 | 412.25 |
Grouping by DATE(created_at) merges orders placed at 08:15:00 and 21:40:00 on the same day into a single summary row.
Common Mistakes & NULL Behavior
Keep these performance and correctness points in mind:
NULLor invalid dates returnNULL: CallingDATE(NULL)orDATE('2026-02-30')returnsNULLrather than raising an error duringSELECT.- Wrapping indexed columns slows
WHEREfilters: Filtering withWHERE DATE(created_at) = '2026-05-12'forces a full table scan because MySQL cannot use a standard index oncreated_at. WriteWHERE created_at >= '2026-05-12 00:00:00' AND created_at < '2026-05-13 00:00:00'instead. - No
TIME-only input: Passing a standalone time likeDATE('14:30:00')has no calendar date and returnsNULL. - String formatting expectations:
DATE()always outputs ISOYYYY-MM-DD. If you need'May 12, 2026', wrap the result inDATE_FORMAT().
Frequently Asked Questions
Does DATE() round up if the time is 23:59:59?
No. DATE() simply truncates the time portion, so '2026-05-12 23:59:59' always returns '2026-05-12'.
Can I use DATE() on a TIMESTAMP column?
Yes. MySQL first converts the TIMESTAMP value to the current session time zone, then extracts the date part.
What happens when I pass a numeric date like 20260512 to DATE()?
MySQL parses valid 8-digit YYYYMMDD integers and returns '2026-05-12', while invalid numbers like 20261301 return NULL.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.