I need to display dates of all Mondays in the given date range.
For example, if my start date is 01/05/2015
and end date is 31/05/2015
, I
SET DATEFIRST 7; -- Set's sunday as first day of week, won't work otherwise
DECLARE @StartDate DATE = '06/01/2015'
DECLARE @EndDate DATETIME = '06/30/2015'
DECLARE @TableOfDates TABLE(DateValue DATETIME)
DECLARE @CurrentDate DATETIME
SET @CurrentDate = @startDate
WHILE @CurrentDate <= @endDate
BEGIN
INSERT INTO @TableOfDates(DateValue) VALUES (@CurrentDate)
SET @CurrentDate = DATEADD(DAY, 1, @CurrentDate)
END
SELECT * FROM @TableOfDates WHERE DATEPART(weekday,Datevalue) = 2