Back to DATA RETRIEVAL & FILTERING

DATE FUNCTIONS

Understand different `DATE` manipulation functions

4 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. EXTRACT Function — The EXTRACT function pulls a specific numerical part from a timestamp for use in aggregation.
  2. DATE_PART Mention — DATE_PART is mentioned as being similar to EXTRACT but is not taught in detail.
  3. DATE_TRUNC Function — DATE_TRUNC resets a timestamp to the beginning of a specified granularity period.
  4. Grouping Context — Extracted or truncated date parts are essential for grouping data in analytical queries.
  5. DATEDIFF Function — DATEDIFF calculates the numerical interval between two timestamps based on a chosen unit.
PDF notes

Frequently asked questions

Why use DATE_TRUNC instead of just EXTRACT(YEAR)?

DATE_TRUNC returns a sortable timestamp that represents the exact start of the year (2024-01-01 00:00:00), whereas EXTRACT returns only the year number (2024).

Can I use EXTRACT for grouping?

Yes, EXTRACT is ideal for grouping, such as counting events by the hour of the day or the day of the week, as it provides a clean numerical category.

What happens to the time components if I truncate to 'day'?

The hour, minute, and second components of the timestamp are all set to 00:00:00, effectively giving you the midnight timestamp for that day.

Is DATE_PART the same as EXTRACT?

They are very similar and often interchangeable depending on the SQL dialect, but EXTRACT is the function detailed in this lesson.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.