Leave a base: Set Ansi_nulls On
Go
Set Quoted_identifier On
Go
-- ========================================================== =====
-- Author: rickylin
-- Create Date: 2007-11-27
-- Description: gets the date of the first day of a month.
-- ========================================================== =====
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: gets the date of the last day of a month.
-- ========================================================== =====
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