DATE_TRUNC()

SQL · Date Functions

Theory

DATE_TRUNC rounds a date or timestamp down to the start of a unit. DATE_TRUNC('month', '2026-11-05') gives 2026-11-01, DATE_TRUNC('year', ...) gives 2026-01-01, and DATE_TRUNC('hour', '14:37:12') gives 14:00:00. Unlike EXTRACT, which returns just the number 11, DATE_TRUNC returns a real date that still contains the year, so November 2025 and November 2026 stay separate.

This makes it the standard tool for time-series reports: GROUP BY DATE_TRUNC('month', order_date) gives one row per calendar month. PostgreSQL and Snowflake use DATE_TRUNC('month', d), BigQuery writes DATE_TRUNC(d, MONTH), and SQL Server offers DATETRUNC(month, d) or the older DATEFROMPARTS(YEAR(d), MONTH(d), 1). SQLite has no DATE_TRUNC, but strftime('%Y-%m-01', d) or date(d, 'start of month') produces the same first-of-month value. Week truncation usually starts on Monday, but check your database setting.

Why we use it

Daily data is too detailed for most reports. DATE_TRUNC buckets every date into its week, month or year start, so you can group and chart totals over time with correct, sortable period labels.

When to use it

Use it for monthly or weekly rollups, cohort analysis and time-series charts. Use EXTRACT when you only want a number (month 11) for seasonality across years, and TO_CHAR only to label the final output.

How it works

  1. Date or timestamp, e.g. 2026-11-05 14:37
  2. Choose the unit: hour, day, week, month, year
  3. Reset every smaller part to its start (day 01, 00:00)
  4. Return a real date: 2026-11-01
  5. Building a report? Yes: GROUP BY the truncated date. No: Use it as a period label.
  6. One row per period

Syntax

DATE_TRUNC('unit', date)

Example

SELECT DATE_TRUNC('month', hire_date) FROM employees;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic