sqlcmd.net validated sql reference
beginner date-time MySQL MariaDB SQL Server PostgreSQL SQLite

Convert Timestamps To Dates

Strip the time portion from a timestamp so only the calendar date remains.

Docker-validated Not currently validation-green

Return only the date portion of a timestamp

The time portion is discarded, which is useful when the query only cares about the day.

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');
Shared across supported engines.
SQL
SELECT
  CAST(created_at AS DATE) AS event_date
FROM
  events;
Returned rows for the shared example.
event_date
2024-04-11

All four engines return the same date-only value for this cast.

Where this command helps.

  • grouping or filtering activity by calendar day
  • showing dates in reports without time-of-day noise

What the command is doing.

Converting a timestamp to a date is useful when you want day-level grouping, filtering, or display without the time component. A cast is often the simplest way to reduce a timestamp to its date portion.