Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add the days in current date using asp.net [closed]

i want to add the days to the current date for example i want to input the days in digits and than i select the days in which i want to add in current date means days, weeks and month but when i select the days or weeks or month it shows the days but can not add them in current date can any one help me plz

 protected void TextBoxPredictDays_TextChanged(object sender, EventArgs e)
        {
            string selectPredictDays = DropDownList1.SelectedItem.Value;
            String Days1;
            int Result;
            Days1 = TextBoxPredictedClosing.ToString();
            if (selectPredictDays == "Days")
            {

                Result = Convert.ToInt32(TextBoxPredictDays.Text) * 1;
                TextBoxPredictedClosing.Text = Result.ToString();

            }
            else if (selectPredictDays == "Weeks")
            {

                Result = Convert.ToInt32(TextBoxPredictDays.Text) * 7;
                TextBoxPredictedClosing.Text = Result.ToString();
            }
            else if (selectPredictDays == "Months")
            {

                Result = Convert.ToInt32(TextBoxPredictDays.Text) * 30;
                TextBoxPredictedClosing.Text = Result.ToString();
            }

        }

here is my design code

 <asp:TextBox ID="TextBoxPredictDays" runat="server" 
            ontextchanged="TextBoxPredictDays_TextChanged"  Width="101px" Height="14px" ></asp:TextBox>
      <asp:DropDownList ID="DropDownList1" runat="server" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>Days</asp:ListItem>
            <asp:ListItem>Weeks</asp:ListItem>
            <asp:ListItem>Months</asp:ListItem>
        </asp:DropDownList>
like image 475
Ismail Avatar asked Dec 14 '15 11:12

Ismail


People also ask

How to add days in current date in asp net?

Firstly, get the current date. Now, use AddDays() method to add days to the current date.

How to add days in current DateTime in C#?

The DateTime. AddDays() method in C# is used to add the specified number of days to the value of this instance. This method returns a new DateTime.

How to add date in C# net?

AddDays() Method in C# This method is used to return a new DateTime that adds the specified number of days to the value of this instance. Syntax: public DateTime AddDays (double value);


3 Answers

DateTime.Now.AddDays(int) - for days
DateTime.Now.AddDays(int * 7) - for weeks
DateTime.Now.AddMonths(int) - for months

like image 124
Konstantin Zadiran Avatar answered Oct 19 '22 23:10

Konstantin Zadiran


DateTime dt = DateTime.Now.AddDays(int); Days
dt = DateTime.Now.AddMonths(int);  Months
dt = DateTime.Now.AddDays(int * 7); Week
like image 23
Dilip Oganiya Avatar answered Oct 19 '22 23:10

Dilip Oganiya


This is what your method would look like:

protected void TextBoxPredictDays_TextChanged(object sender, EventArgs e)
        {
            string selectPredictDays = DropDownList1.SelectedItem.Value;
            if (selectPredictDays == "Days")
            {
                TextBoxPredictedClosing.Text = DateTime.Now.AddDays(Convert.ToInt32(TextBoxPredictDays.Text));
            }
            else if (selectPredictDays == "Weeks")
            {
                TextBoxPredictedClosing.Text = DateTime.Now.AddDays(Convert.ToInt32(TextBoxPredictDays.Text) * 7);
            }
            else if (selectPredictDays == "Months")
            {
                TextBoxPredictedClosing.Text = DateTime.Now.AddMonths(Convert.ToInt32(TextBoxPredictDays.Text));
            }
        }
like image 31
sachin Avatar answered Oct 20 '22 00:10

sachin