Example 1
Return only the date portion of a timestamp
The time portion is discarded, which is useful when the query only cares about the day.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE events (created_at DATETIME);
INSERT INTO
events (created_at)
VALUES
('2024-04-11 09:30:00');Validated query Shared across supported engines.
SQL
SELECT
CAST(created_at AS DATE) AS event_date
FROM
events;Expected result Returned rows for the shared example.
| event_date |
|---|
| 2024-04-11 |
All four engines return the same date-only value for this cast.