---
title: "SQL: How to Drill Down Timestamp with DATE_TRUNC Function"
description: "The best example for TRUNC function that truncates to nearest date format in SQL"
url: https://srinimf.com/2017/01/22/how-trunc-function-better-idea-for-numeric-date/
date: 2017-01-22
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2017/01/pexels-photo-6032418.jpeg?fit=1880%2C1255&ssl=1
categories: ["Oracle", "SQL"]
tags: ["SQL Functions"]
type: post
lang: en
---

# SQL: How to Drill Down Timestamp with DATE_TRUNC Function

Here’s an example [to extract](https://srinimf.com/2023/12/27/how-to-get-date-and-time-from-timestamp-in-db2/) **year** [from timestamp](https://srinimf.com/2017/01/05/how-to-extract-date-from-timesmp/) using DATE_TRUNC function.

Related[SQL EXTRACT Function: How to Get Month, Day, Year](https://srinimf.com/2019/01/28/db2-date-sql-queries-to-use-in-your-current-project/)

## DATE_TRUCN Function

DATE_TRUNC ( PERIODIC_DATE, YEAR)

The TRUNC function truncates DATE to year. The input DATE is YYYY-MM-DD. After TRUNC function, it changes to YEAR. That means to YYYY-01-01.

Related[How to Work With DATE FORMAT: Top MySQL Examples](https://srinimf.com/2024/10/03/how-to-work-with-date-format-top-mysql-examples/)

Uses of DATE_TRUNC Function

- This function most frequently being used in data warehousing projects.
- This is one of the best way to work with Date related functions.

References

- [More examples of DATE_TRUNC](https://mode.com/blog/date-trunc-sql-timestamp-function-count-on/)

Related Posts

- [DB2 DATE and Time Conversion: Top SQL Queries](https://srinimf.com/2022/10/22/how-to-understand-db2-date-and-time-sql-queries/)DateOctober 22, 2022
- [SQL Numeric Functions Easy Ways to Use](https://srinimf.com/2018/04/01/sql-query-numeric-function-used-in-real-time-banking-project/)DateApril 1, 2018
- [SQL Built-in Functions to write better query](https://srinimf.com/2015/07/15/mainframe-simplify-your-db2-sql-query-with-these-built-in-functions/)DateJuly 15, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2017%2F01%2F22%2Fhow-trunc-function-better-idea-for-numeric-date%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2017%2F01%2Fpexels-photo-6032418.jpeg%3Ffit%3D1200%252C801%26ssl%3D1&description=SQL%3A%20How%20to%20Drill%20Down%20Timestamp%20with%20DATE_TRUNC%20Function)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2017/01/22/how-trunc-function-better-idea-for-numeric-date/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2017/01/22/how-trunc-function-better-idea-for-numeric-date/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2017/01/22/how-trunc-function-better-idea-for-numeric-date/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2017/01/22/how-trunc-function-better-idea-for-numeric-date/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20SQL%3A%20How%20to%20Drill%20Down%20Timestamp%20with%20DATE_TRUNC%20Function&body=https%3A%2F%2Fsrinimf.com%2F2017%2F01%2F22%2Fhow-trunc-function-better-idea-for-numeric-date%2F&share=email)
-

### Like this:

Like Loading…
