-->

Friday, April 18, 2014

Add months in existing date example in ASP.NET

 Add months in existing date example in ASP.NET

Introduction

Using AddMonths method  you can add months in integer, Object will be updated with new date. This method is used where you want to calculate date after some months. Like Library management project. Lets take an simple example


<form id="form1" runat="server">
    <div>  
        <asp:Button ID="Button1"
        runat="server"
        onclick="Button1_Click"
        Text="Click"
        BackColor="#99CCFF" />  
    </div>
        <asp:Label ID="Label1"
        runat="server"
        BackColor="Yellow"></asp:Label>
    </form>
CodeBhindeCode-
 protected void Button1_Click(object sender, EventArgs e)  
        {        
            DateTime now = DateTime.Now;        
            DateTime after3Months = now.AddMonths(3);
            Label1.Text = "now = " + now.ToLongDateString();
            Label1.Text += "<br /><br />after added 3 months to now= ";
            Label1.Text += after3Months.ToLongDateString();

        }
OutPut
 Add months in existing date example in ASP.NET

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved