Arun S


Hi

How do I get max day/date of the month for a given date. ie my given date is 12/14/2006. This is december 2006 so the max day is 31.

Thanks in advance

Arun



Re: Max date

timvw


Basically, you want the last day of month (or the day before the first of the next month)..

        static int LastDayOfMonth( DateTime dateTime )
        {
            int year = dateTime.Year;
            int month = dateTime.Month + 1;
            if( month == 13 )
            {
                ++year;
                month = 1;
            }

            return new DateTime( year,month, 1 ).AddDays( -1 ).Day;
        }