Rajendra Gupta shows off a nice feature in SQL Server 2022:
Suppose you are a data strategist or analyst for an organization. You have been tasked with getting actionable insights from customers who want to track customer patterns at different intervals, such as hourly, daily, or weekly. To do this, you need to use several date functions such as DATEADD, DATEDIFF, DATEPART, and DATEFROMPARTS to get the required date format.
In SQL Server 2022, this got a lot easier to do using the DATETRUNC function.
Solutions using DATETRUNC()
are significantly easier to read and understand than the alternative of combiningDATEADD()
and DATEDIFF()