ALTER FUNCTION [dbo].[GetYearlyDays]
(
@stDate date,
@endDate date,
@year int
)
RETURNS int
AS
BEGIN
DECLARE @noOfdays int
SELECT @noOfdays=count(year(CurrentDate))
FROM (SELECT TOP (DATEDIFF(DAY, @stDate, @endDate) + 1)
CurrentDate = DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY A.object_id) - 1, @stDate)
FROM sys.all_objects A) AS B
Where year(CurrentDate)=2020
group by year(CurrentDate)
RETURN @noOfdays
END
Call : select [dbo].[GetYearlyDays] ('01-01-2021','01-12-2021',2021)
0 Comments