Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have two dropdownlist year and month..
when i have select the month and year..getthe no of days in a month ....in c sharp.
pls reply me
Posted

try this.. :)

C#
int days = DateTime.DaysInMonth(int Year,int Month);


where you can write Year and month in Integer

E.G.

C#
int days = DateTime.DaysInMonth(2014,2);


This will return 28 Days
 
Share this answer
 
v2
You can use javascript for this

C#
function daysInMonth(month,year)
{
   return new Date(year, month, 0).getDate();
}


If you want it to be done using c sharp ,call the below method using Ajax or on drop down change event.

C#
public int GetDays(int year, int month){
return DateTime.DaysInMonth(year, month);
}
 
Share this answer
 
Comments
CHill60 29-May-14 5:56am    
Does that javascript really return the number of days in a month?
soumyajayaraj 29-May-14 5:59am    
Yes
CHill60 29-May-14 6:13am    
That's cool! Learned something. Thanks
Thanks7872 29-May-14 6:41am    
Good one..!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900