How many days in a month ?

To findout how man days in a particular month

If Object_Id('Dbo.HowManyDays') Is Not Null
Drop Function Dbo.HowManyDays
Go
Exec(
'Create Function Dbo.HowManyDays(@Year Int,@Month Varchar(15)) Returns Int
As
Begin
Declare @Date Varchar(50),
@Days TinyInt
 Select @Date = Cast(@Year as Varchar) + ''-'' + @Month + ''-01'',
@Days = DatePart(Day,DateAdd(Month,1,@Date) -1)
 Return @Days
End')

--How to Execute it
Select Dbo.HowManyDays(2011, 'June') [Days]
Go


No comments:

Post a Comment