First you need to pass the date in Proper Format so you can use the datetime value to compare and add it to the table.
Refer the below test query for your reference and implement it in your code as per your logic.
SQL
CREATE TABLE #Dates(Dates Datetime)
DECLARE @Start DATETIME
DECLARE @End DATETIME
SET @Start = '11/01/2017' -- IN MM/DD/YYYY format
SET @End = '11/30/2017' -- IN MM/DD/YYYY format
DECLARE @Counter INT, @TotalCount INT
SET @Counter = 0
SET @TotalCount = DateDiff(DD,@Start,@End)
WHILE (@Counter <=@TotalCount)
BEGIN
DECLARE @DateValue DATETIME
SET @DateValue= DATEADD(DD,@Counter,@Start)
INSERT INTO #Dates(Dates)
VALUES(@DateValue)
SET @Counter = @Counter + 1
END
SELECT * FROM #Dates
Output
Dates |
2017-11-01 00:00:00.000 |
2017-11-02 00:00:00.000 |
2017-11-03 00:00:00.000 |
2017-11-04 00:00:00.000 |
2017-11-05 00:00:00.000 |
2017-11-06 00:00:00.000 |
2017-11-07 00:00:00.000 |
2017-11-08 00:00:00.000 |
2017-11-09 00:00:00.000 |
2017-11-10 00:00:00.000 |
2017-11-11 00:00:00.000 |
2017-11-12 00:00:00.000 |
2017-11-13 00:00:00.000 |
2017-11-14 00:00:00.000 |
2017-11-15 00:00:00.000 |
2017-11-16 00:00:00.000 |
2017-11-17 00:00:00.000 |
2017-11-18 00:00:00.000 |
2017-11-19 00:00:00.000 |
2017-11-20 00:00:00.000 |
2017-11-21 00:00:00.000 |
2017-11-22 00:00:00.000 |
2017-11-23 00:00:00.000 |
2017-11-24 00:00:00.000 |
2017-11-25 00:00:00.000 |
2017-11-26 00:00:00.000 |
2017-11-27 00:00:00.000 |
2017-11-28 00:00:00.000 |
2017-11-29 00:00:00.000 |
2017-11-30 00:00:00.000 |