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

preview_player
Показать описание
In this tutorial, you'll learn how to use the DATE_TRUNC function in SQL to optimize queries using dates!

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

Support the Channel:
Рекомендации по теме
Комментарии
Автор

Thank you so much for breaking this down into simple words to connect the concepts for us N00bs!!! Greatly appreciate the effort you put in dude. A thousand thank you's friend!!!!

PhoenixJade
Автор

Great tutorial. Precise and easy to understand

kanknw
Автор

Just what I needed and you explained very well and in simple.
Thank you so much

mdimranhussain
Автор

thanks helped me with date formatting.

skkitchenstore
Автор

Can we use date_diff('day', return_date, rental_date)
???

reigngamer
Автор

In python, I'd just use a data type converter to convert the day back to a numeric. Would I be correct in saying that an alternative method would be to use the CAST function to do a similar job in Postgres SQL?

ssol
Автор

Hi again. Which is better in general between SQL Server and PostgreSQL - which I realized is what you're using

joshsmart
Автор

Am I able to group by the product of a distinct 'day' date?

mhuppman
Автор

How do you then filter on these dates (i.e. greater than or between dates x & y)?

mhuppman
Автор

Just so you'll know, some of your links led to a demand for $399. The PC became locked and demanded a fake call to Microsoft. I got out of it by signing off the PC. I'm sure you had nothing to do with it.

michaelbradford
join shbcf.ru