In this article, we will learn how to get a total number of days in the month in c#. There are two built-in methods to get the total number of days in a month. The first method is DateTime.DaysInMonth(year, month)
and the second method is CultureInfo.CurrentCulture.Calendar.GetDaysInMonth(year,month)
.
Here are these examples to get the number of days in a month as follows:
Example 1: In this example, we will use DateTime.DaysInMonth(year, month)
and this method takes two parameters: year and month.
Total Number of Days in Month: 29 Days
Example 2: In this example, we will use CultureInfo.CurrentCulture.Calendar.GetDaysInMonth(year,month)
and this method takes two parameters: year and month. For this method, you need to use System.Globalization
namespace.
Total Number of Days in Month: 29 Days
I hope this article will help you to understand how to get a total number of days in the month in c#.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments