留個底:SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: RickyLin
-- Create date: 2007-11-27
-- Description: 擷取某年某月的第一天的日期
-- =============================================
ALTER FUNCTION fnGetFirstDayOfMonth
(
@Year SMALLINT
, @Month TINYINT
)
RETURNS SMALLDATETIME
AS
BEGIN
DECLARE @FirstDay SMALLDATETIME
DECLARE @Str VARCHAR(10)
SET @Str = Cast(@Year AS VARCHAR(4)) + '-' + Cast(@Month AS VARCHAR(2)) + '-1'
SET @FirstDay = Convert(SMALLDATETIME, @Str)
RETURN @FirstDay
END
GO
-- =============================================
-- Author: RickyLin
-- Create date: 2007-11-27
-- Description: 擷取某年某月的最後一天的日期
-- =============================================
CREATE FUNCTION fnGetLastDayOfMonth
(
@Year SMALLINT
, @Month TINYINT
)
RETURNS SMALLDATETIME
AS
BEGIN
DECLARE @LastDay SMALLDATETIME
DECLARE @Str VARCHAR(10)
SET @Str = Cast(@Year AS VARCHAR(4)) + '-' + Cast(@Month AS VARCHAR(2)) + '-1'
SET @LastDay = DateAdd(d, -1, DateAdd(m, 1, dbo.fnGetFirstDayOfMonth(@Year, @Month)))
RETURN @LastDay
END
GO