SQL Server 2022 brings some exciting new language features such as DATE_BUCKET
SELECT DATE_BUCKET(HOUR, 1, GETUTCDATE()) AS Bucket_Now
As per the information, this function returns the date-time value corresponding to the start of each date-time bucket. This means it much easier and more readable now to bucket into hours, days, weeks.
In our example above the UTC time is 14:15 and we’ve chosen hour buckets
The result from above is:
Thanks for reading!