Learn SQL/Intermediate/Date & Time/SQL Timestamp to Date

SQL Timestamp to Date

Drop the time-of-day component from a TIMESTAMP, keeping only the calendar date — a simple, common cast.

What & Why

Casting a TIMESTAMP to DATE (timestamp_column::DATE) discards the time-of-day entirely, keeping only the calendar date. Useful whenever a report needs to group or compare by day, ignoring exactly what time an event happened.

See How It Works

BUSINESS QUESTION

Product wants feedback grouped by calendar date.

iduser_idfeature_idratingnps_scorecommentcreated_at
1101159Clear and useful2024-01-25 12:15:00+00
210224NULLExport worked well2024-02-20 15:40:00+00
3103147Helpful setup flow2024-03-18 09:05:00+00
410433NULLNeeds clearer timing2024-04-08 17:30:00+00
EXAMPLE QUERY
SELECT
  created_at::date AS feedback_date,
  COUNT(*) AS feedback_count
FROM product.feedback
GROUP BY feedback_date
ORDER BY feedback_date;
RESULT — exact output from the displayed Queryflo rows
feedback_datefeedback_count
2024-01-251
2024-02-201
2024-03-181
2024-04-081

Casting creates four actual feedback dates before grouping.

Now You Try

Practice this concept

Product wants feedback grouped by calendar date.

Available schema
product

Prefix tables with product.table_name.

feedback_datefeedback_count
product.feedback
ColumnType
idinteger
user_idinteger
feature_idinteger
ratinginteger
nps_scoreinteger
commenttext
created_attimestamp with time zone
moderation_buckettext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario