【取月的第1天】
create Function [dbo].[F_FirstDayOfTheMonth]
(
@Year int, -- 年度
@Month int -- 月份
)
RETURNS DateTime
AS
BEGIN
DECLARE @FirstDay DateTime
set @FirstDay = Convert(DateTime, Str(@Year,4) + '-' + Str(@Month, 2) + '-01');
return(@FirstDay)
END
【取月的最后1天】
create Function [dbo].[F_LastDayOfTheMonth]
(
@Year int, -- 年度
@Month int -- 月份
)
RETURNS DateTime
AS
BEGIN
DECLARE @FirstDay DateTime
set @FirstDay = Convert(DateTime, Str(@Year,4) + '-' + Str(@Month, 2) + '-01');
DECLARE @LastDay DateTime
Set @LastDay = DateAdd(Day, -1, DATEADD(Month, 1, @FirstDay))
return(@LastDay)
END