Get only Saturday and Sunday dates of month in SQL Server

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stellar Meta

Q&A about the site for developers and users of Stellar and the Stellar Distributed Exchange

DECLARE @month date = '2022-08-01'

SET @month = dateadd(month, datediff(month, 0, @month), 0)

;WITH CTE as
(
  SELECT 0 x
  FROM (values(1),(1),(1),(1),(1),(1)) x(n)
),
CTE2 as
(
  SELECT 
    top(datediff(d, @month,dateadd(month,1,@month))) 
    cast(dateadd(d, row_number()over(order by(select 1))-1,@month) as date) cDate
  FROM CTE CROSS JOIN CTE C2
)
SELECT
  cDate, 
  datename(weekday, cDate) Weekday
FROM CTE2
WHERE 
  datediff(d,0,cDate)%7 > 4

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results