How to use the DATE_TRUNC Function in SQL (vs. TO_CHAR)

Published: 12 January 2020
on channel: Becoming a Data Scientist
24,289
546

In this tutorial, you'll learn how to use the DATE_TRUNC function in SQL to optimize queries using dates!

Watch the TO_CHAR video:    • Using the TO_CHAR function in SQL Cha...  

Queries:
1) Truncate for the day: SELECT date, DATE_TRUNC('day',date) FROM table
2) Do some truncated date math: SELECT DATE_TRUNC('day',date1)-DATE_TRUNC('day',date2) FROM table

Get the Pagila Database:    • How to Load a Sample PostgreSQL Datab...  

Support the Channel:
1) Subscribe:
2) DataCamp:
3) Udacity: