c# - How to add 1 month to a given DateTime object

DateTime add 1 month
this is a .net date time related example. in this example we see how to add month(s) in a date time object. first we create a date time object using built in now function. then add one month to this date time variable. finally example show the addition result. all process done programmatically by a button click event.
datetime-add-1-month.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">    
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        //initialize a datetime variable with current date time
        DateTime now = DateTime.Now;
        
        //this line added one month with current datetime object.
        DateTime after1Month = now.AddMonths(1);

        Label1.Text = "now : " + now.ToLongDateString();
        
        Label1.Text += "<br /><br />after added 1 month to now.........<br />";
        Label1.Text += after1Month.ToLongDateString();
    }
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <title>c# example - datetime add 1 month</title>      
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            c# example - datetime add 1 month
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <asp:Label       
            ID="Label1"       
            runat="server"      
            Font-Size="X-Large"    
            >      
        </asp:Label>      
        <br /><br />    
        <asp:Button       
            ID="Button1"       
            runat="server"       
            Text="add one month to current date time"      
            OnClick="Button1_Click"    
            Height="40"      
            Font-Bold="true"      
            />      
    </div>      
    </form>      
</body>      
</html>
More c# examples