locked
Alert if Current date is previous then 4 days RRS feed

  • Question

  • User-807418713 posted

    Hi

    I have textbox1 in which I have a value for example

    01-Dec-2019

    In textbox2 I have 06-Dec-2019

    Now on button click I want to show you have exceed more then 4 days from Current date.

    Thank you

    Friday, December 6, 2019 5:30 AM

Answers

  • User-1780421697 posted
    C#:
      protected void btn_Click(object sender, EventArgs e)
            {
                DateTime StartDate = DateTime.Parse(txt1.Text);
                DateTime EndDate = DateTime.Parse(txt2.Text);
    
                int days = ((EndDate.Date - StartDate.Date).Days)-1;
    
                lbl.Text = $"you have exceed more then {days.ToString()} days from Current date";
            }
      
    //.aspx 
    
    
    <asp:TextBox id="txt1" runat="server"></asp:TextBox>
    <asp:TextBox id="txt2" runat="server"></asp:TextBox>
    <asp:Button ID="btn" runat="server" Text="Validate" OnClick="btn_Click" />
    
    
    <asp:Label id="lbl" runat="server"></asp:Label>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 6:38 AM
  • User-719153870 posted

    Hi Gopi.MCA,

    Now on button click I want to show you have exceed more then 4 days from Current date.

    This can be done with jquery very easily. Please refer to below demo:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.3.1.min.js"></script>
        <script>
            function check() {
                var start = new Date($('#TextBox1').val())
                var end = new Date($('#TextBox2').val())
                var exceed = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)
                alert("you have exceed more then " + (exceed-1) + " days from Current date");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server" Text="01-Dec-2019"></asp:TextBox>
                <asp:TextBox ID="TextBox2" runat="server" Text="06-Dec-2019"></asp:TextBox>
                <input type="button" value="Run" onclick="check()" />
            </div>
        </form>
    </body>
    </html>

    Below is the result:

    Actually, the number of days between 01-Dec-2019 and 06-Dec-2019 should be 5. No matter what, the number will be exptected which is 4.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 6:49 AM

All replies

  • User-1780421697 posted
    C#:
      protected void btn_Click(object sender, EventArgs e)
            {
                DateTime StartDate = DateTime.Parse(txt1.Text);
                DateTime EndDate = DateTime.Parse(txt2.Text);
    
                int days = ((EndDate.Date - StartDate.Date).Days)-1;
    
                lbl.Text = $"you have exceed more then {days.ToString()} days from Current date";
            }
      
    //.aspx 
    
    
    <asp:TextBox id="txt1" runat="server"></asp:TextBox>
    <asp:TextBox id="txt2" runat="server"></asp:TextBox>
    <asp:Button ID="btn" runat="server" Text="Validate" OnClick="btn_Click" />
    
    
    <asp:Label id="lbl" runat="server"></asp:Label>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 6:38 AM
  • User-719153870 posted

    Hi Gopi.MCA,

    Now on button click I want to show you have exceed more then 4 days from Current date.

    This can be done with jquery very easily. Please refer to below demo:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.3.1.min.js"></script>
        <script>
            function check() {
                var start = new Date($('#TextBox1').val())
                var end = new Date($('#TextBox2').val())
                var exceed = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)
                alert("you have exceed more then " + (exceed-1) + " days from Current date");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server" Text="01-Dec-2019"></asp:TextBox>
                <asp:TextBox ID="TextBox2" runat="server" Text="06-Dec-2019"></asp:TextBox>
                <input type="button" value="Run" onclick="check()" />
            </div>
        </form>
    </body>
    </html>

    Below is the result:

    Actually, the number of days between 01-Dec-2019 and 06-Dec-2019 should be 5. No matter what, the number will be exptected which is 4.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 6:49 AM