Friday, May 23, 2014

How to get total days of month in c#

6:23 AMFriday, May 23, 2014
If you want to find total days in current month then you should use DayInMonth( ) method of DateTime structure. In this method you should pass the year and month, which you want to access total days of the month. Lets take an simple example to find total days of a month

Source Code

<form id="form1" runat="server">
        <asp:Button ID="Button1"
         Text="Click" />  
       <asp:Label ID="Label1"

Code Behind

protected void Button1_Click(object sender, EventArgs e)
            DateTime today = DateTime.Today;          
            int TotalOfDays = DateTime.DaysInMonth(today.Year, today.Month);
            Label1.Text = "today : " + today.ToLongDateString();
            Label1.Text += "<br /><br />Total days in month=";
            Label1.Text += TotalOfDays;

Code Generate the following output
How to get total days of month in c#

Protected by Copyscape Online Copyright Protection Software


Post a Comment

Toggle Footer