Introduction
Sometimes, a business requires all days with date between two dates. There are many ways to get this done, but I am introducing a very simple way to do this using SQL Server.
Using the Code
Create PROCEDURE getAllDaysBetweenTwoDate
(
@FromDate DATETIME,
@ToDate DATETIME
)
AS
BEGIN
DECLARE @TOTALCount INT
SET @FromDate = DATEADD(DAY,-1,@FromDate)
Select @TOTALCount= DATEDIFF(DD,@FromDate,@ToDate);
WITH d AS
(
SELECT top (@TOTALCount) AllDays = DATEADD(DAY, ROW_NUMBER()
OVER (ORDER BY object_id), REPLACE(@FromDate,'-',''))
FROM sys.all_objects
)
SELECT AllDays From d
RETURN
END
GO