With SQL Server, when you want to create a date scheduled for the month or year, you maybe add them one by one to the table. But this article, you can generate dates schedule between date ranges. It’s easy and useful for creating by set the start date and end date.

So if you want to get a date scheduled in a table, please check the SQL query below.

SQL Server Contents:

Dates schedule

For this example 1, I need date lists from 01/09/2021 to 07/09/2021. For date generation query :

SELECT GDATE.DATE FROM (SELECT TOP (DATEDIFF(DAY, '2021-09-01', '2021-09-07') + 1)
DATE = DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, '2021-09-01')
FROM sys.all_objects a CROSS JOIN sys.all_objects b) GDATE

Final Result :

For this example 2, I need date lists from 01/01/2022 to 28/02/2022. For date generation query :

SELECT GDATE.DATE FROM (SELECT TOP (DATEDIFF(DAY, '2022-01-01', '2022-02-28') + 1)
DATE = DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, '2022-01-01')
FROM sys.all_objects a CROSS JOIN sys.all_objects b) GDATE