Learner
Learner

Reputation: 1644

Any way to get the no of days for a particular month?

Actually i want to add name of months(Using C sharp) along with value in drop down list and i want to add it pro-grammatically.I have get the method to display the name but for a particular month how to get the maximum number of days in it?

Upvotes: 1

Views: 997

Answers (3)

Gour Chandra Das
Gour Chandra Das

Reputation: 1

 Exec SpYearResult 2016 go Alter Procedure SpYearResult (@Year Int) as Begin Declare @Date dateTime; Declare @intValue int; declare @Test Table (Mon Varchar(50),DaysInMonth int) ; Set @intValue = 0 While @intValue <12 Begin SET @Date = Convert(Datetime,Convert(Varchar(4),@Year)+'-01-01') SET @date = DATEADD(mm,@intValue, @Date); INSERT INTO @Test SELECT DateName(mm,@date)+'-' +Convert(Varchar(4),@Year) as Mon, DAY(EOMONTH(@date)) AS DaysInMonth set @intValue = @intValue +1 End select * from @Test End

Upvotes: -1

KV Prajapati
KV Prajapati

Reputation: 94653

DaysInMonth method.

int days=DateTime.DaysInMonth(2010,1);

Upvotes: 4

Aliostad
Aliostad

Reputation: 81700

Use

  DateTime.DaysInMonth(1969, 11);

Upvotes: 3

Related Questions