Click here to Skip to main content
14,459,186 members
Rate this:
Please Sign up or sign in to 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
Rate this:
Please Sign up or sign in to vote.

Solution 1

try this.. :)

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


where you can write Year and month in Integer

E.G.

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


This will return 28 Days
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can use javascript for this

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.

public int GetDays(int year, int month){
return DateTime.DaysInMonth(year, month);
}
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100