This method returns the number of days in the specified month and year. This method always interprets month and year as the month and year of the Gregorian calendar even if the Gregorian calendar is not the current culture’s current calendar.
public static int DaysInMonth (int year, int month);
Return Value: This method return the number of days in the month for the specified year. For example, if month equals 2 for February, the return value will be 28 or 29 depending upon whether the year is a leap year.
Exception: This method will give ArgumentOutOfRangeException if month is less than 1 or greater than 12 or year is less than 1 or greater than 9999.
Below programs illustrate the use of the above-discussed method:
31 29 28
System.ArgumentOutOfRangeException: Year must be between 1 and 9999.
Parameter name: year
- Difference between Method Overriding and Method Hiding in C#
- C# | Join Method | Set - 2
- C# | Method Overriding
- DateTimeOffset.Add() Method in C#
- C# | Join() Method | Set - 1
- Method Hiding in C#
- C# | Math.Pow() Method
- C# | Math.Min() Method
- C# | Math.Max() Method
- C# | Method Parameters
- Decimal.Add() Method in C#
- C# | Math.Abs() Method | Set - 2
- C# | Math.Abs() Method | Set - 1
- C# | Math.Exp() Method
- C# | PadLeft() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.