DATE_TRUNC('month', d)::date AS month_start, -- First day of the month DATE_TRUNC('year', d)::date AS year_start, -- First day of the year EXTRACT(YEAR FROM d)::int ...
Who are these scripts for? You need to troubleshoot performance problems with SQL Server, and you need to do it now. You don't have time to track down a bunch of DMVs, figure out Extended Events, ...