Add weeks in existing date ASP.NET example

Introduction

Using Add Days method  you can add weeks in integer (converts weeks in days), Object will be updated with new date. This method is used where you want to calculate date after some days. Like Library management project. Lets take an simple example

<form id="form1" runat="server">
    <asp:Button ID="Button1"
    runat="server"
    BackColor="#99CCFF"
    onclick="Button1_Click"
    Text="Click" />
    <div>  
    <asp:Label ID="Label1"
    runat="server"
    BackColor="Yellow"></asp:Label>  
    </div>
    </form>
Code Behind 
protected void Button1_Click(object sender, EventArgs e)
        {        
            DateTime today = DateTime.Today;        
            DateTime after2week = today.AddDays(14);            
            DateTime after4weeks = today.AddDays(28);
            Label1.Text = "today= " + today.ToLongDateString();
            Label1.Text += "<br /><br />after added two weeks with today=";
            Label1.Text += after2week.ToLongDateString();
            Label1.Text += "<br /><br />after added 4 weeks with today=";
            Label1.Text += after4weeks.ToLongDateString();

        }
Code generate the following code

Add weeks in existing date ASP.NET example
Posted on by Jackrin Reacher | No comments

0 comments:

Post a Comment