Skip to main content
Module 6 · Lesson 2 of 422/57 in the course~14 min
Module lessons (2/4)

Date and Timestamp Functions

Lesson preview5 hands-on exercises readySQL Course · Module 6 — Built-in Functions

EXTRACT, DATE_TRUNC, intervals, and differences between timestamps.

What you'll learn in this lesson

  • Distinguish DATE, TIMESTAMP, TIMESTAMPTZ and INTERVAL.
  • Aggregate correctly over time with EXTRACT(...) (single component) vs DATE_TRUNC(...) (continuous bucket).
  • Perform temporal arithmetic and filter daily intervals without disabling indexes.

Overview

Dates and times govern orders, shipments, registrations and retention. Choosing the wrong function — for example aggregating with EXTRACT(MONTH ...) instead of DATE_TRUNC('month', ...) — can merge months from different years together into one bucket without any visible error!

View in the stepper how WHERE isolates the target year and immediately afterwards GROUP BY groups the buckets created by DATE_TRUNC('month', ...) before counting them in SELECT:

Sections covered in this lesson

  1. 11. Mental Model: Components vs Temporal Buckets
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: Temporal Buckets in GROUP BY
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 6 — Built-in Functions

Unlock "Date and Timestamp Functions" and the full SQL Course curriculum

EXTRACT, DATE_TRUNC, intervals, and differences between timestamps.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.