SQL: How to Drill Down Timestamp with DATE_TRUNC Function

Here’s an example to extract year from timestamp using DATE_TRUNC function.

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.

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

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.