Dear Brother's
Do you have any idea that how can i get total days of current month. current month is feb than totalday must be 28 and if current mont is marach than totalday must be 31.. I need this function. please help me reagrding this problem.. thanks in advance
best regrads
Waqar Hussain Laghari

Praveen KumarRank #4 · 79.9K reputationPosted Mar 31, 2009, 2:02 AM EDT
int
noofdays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);Robert4 reputationPosted Mar 31, 2009, 2:10 AM EDT
Hi,
This should work
int
numDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);Best regards
Robert
vivek kulkarni132 reputationPosted Mar 31, 2009, 2:14 AM EDT
Hi,
Here is how you can write a function. Use an arralist to define all the days in month one after the other upto 12.
arr.Add(31);
arr.Add(28);
arr.Add(31);
arr.Add(30);
.......................
you can directly access the days by using the index in the array square bracket.
Here is a function to calculate the leap year for getting the days in feb.
private bool CheckLeapYear ( int year )
{
bool leapYear = false;
leapYear = ( ( ( year % 4 ) == 0 ) && ( ( year % 100 ) != 0 ) || ( ( year % 400 ) == 0 ) );
if ( leapYear.Equals ( true ) )
return true;
else
return false;
}
Thank you
waqar laghari62 reputationPosted Mar 31, 2009, 3:19 AM EDT
Thanks brothers.
int numDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
but this function actually calcuate the current month's days. But brother i want to find out the cunrentMonth -1 month. do you have any idea about it..
Thanks
Best regards
Waqar Hussain Laghari
waqar laghari62 reputationPosted Mar 31, 2009, 3:35 AM EDT
Thank you very much.. I got result using following function.
int days = DateTime.DaysInMonth(CurrentY, CurrentM);Again thanks for all replies..
Best regards
Waqar Hussain laghari
vira trivedi2 reputationPosted Mar 16, 2010, 3:36 AM EDT
Jiyaul MustaphaRank #5,573 · 294 reputationPosted Aug 17, 2019, 1:48 AM EDT