c# - How to get month from a date

Get month from DateTime
The following example code demonstrate us how can we get the month part/component from a dateTime object programmatically at run time. .Net framework's DateTime.Month property allow us to get the month part of the date represented by this instance. DateTime is exists in .Net Framework's System namespace.

DateTime.Month property return a System.Int32 data type value. This return integer number represent the month component of the provided DateTime instance. This return integer value is a number between 1 to 12 where 1 represent January, 2 represent February and so on. The provided output image help you more to better understand this tutorial.
Month.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        DateTime myDateTime = DateTime.Now;
        string month = myDateTime.Month.ToString();

        Label1.Text = "My DateTime: " + DateTime.Now.ToLongDateString();
        Label1.Text += "<br />Month: " + month;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>asp.net date time example: how to get month from a date time object in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">asp.net date time example: Month</h2>
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Size="Larger"
             Font-Italic="true"
             Font-Bold="true"
             ForeColor="Violet"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             Font-Bold="true" 
             ForeColor="Violet" 
             OnClick="Button1_Click"
             Text="Get Month From DateTime Object"
             />   
    </div>
    </form>
</body>
</html>
More c# examples