DATE_BUCKET groups timestamps into hourly, weekly, and custom intervals, with an origin that determines where every boundary lands.
SQL SERVER – UDF – User Defined Function – Get Number of Days in Month
A simple user defined function that returns the number of days in month for any date, with the leap year rule for February built in.
SQL SERVER – Find Monday of the Current Week
Find Monday of the current week with one line of T-SQL: DATEADD and DATEDIFF with the week part and GETDATE() give you the date.
SQL SERVER – Find Last Day of Any Month – Current Previous Next
Find the last day of any month with DATEADD and DATEDIFF. One script returns the last day of the previous, current and next month in SQL Server.
SQL SERVER – UDF – Function to Get Previous And Next Work Day – Exclude Saturday and Sunday
Inspired by a ColdFusion post by Ben Nadel, here is the UDF I use to get the previous or Next Work Day for any date, skipping Saturday and Sunday.
SQL SERVER – UDF – Get the Day of the Week Function
Get the day of the week as a name in SQL Server: a UDF using DATEPART with CASE, plus the simpler DATENAME(dw, GETDATE()) a reader suggested.







