asp.net.ph

DateTime.DaysInMonth Method

System Namespace   DateTime Structure


Returns the number of days in the specified month of the specified year.

[ VB ]
<Serializable>
Public Shared Function DaysInMonth ( _
   ByVal year As Integer, _
   ByVal month As Integer _
} As Integer

[ C# ]
[ Serializable ]
public static int DaysInMonth (
   int year,
   int month
};

[ C++ ]
[ Serializable ]
public: static int DaysInMonth (
   int year,
   int month
};

[ JScript ]
public Serializable
static function DaysInMonth (
   year : int,
   month : int
} : int;

Parameters

year
The year.
month
The month ( a number ranging from 1 to 12 ).

Return Value

The number of days in month for the specified year.

For example, if month equals 2 for February, the return value is 28 or 29 depending upon whether year is a leap year.

Exceptions


Exception Type Condition
ArgumentOutOfRangeException month is less than 1 or greater than 12.

Example

The below code snippet demonstrates using the DaysInMonth method.

const int July = 7;
const int Feb = 2;

// daysInJuly gets 31.
int daysInJuly = System.DateTime.DaysInMonth ( 2001, July );

// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System.DateTime.DaysInMonth ( 1998, Feb );

// daysInFebLeap gets 29 because the year 1996 was a leap year.
int daysInFebLeap = System.DateTime.DaysInMonth ( 1996, Feb );
  C# VB

See Also

DateTime Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph