locked
Filter Without Year RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my table data

    Field1 Ranges
    A 16-Mar - 23-Mar
    B 24-Mar - 30-May
    C 01-Jun - 15-Jun

    1) If user pass any date between this ranges has to show desire out put for example if i pass 27-Mar

    then it has to show B

    2) If user pass any date between this ranges has to show desire out put for example if i pass 19-Mar

    then it has to show A

    How to do so...

    Monday, June 15, 2020 5:25 AM

Answers

  • User-939850651 posted

    Hi, Gopi.MCA

    Based on your description, I created a demo and implemet it. And I chose to handle the comparison operation in the code behind.

    More details, please refer below code:

    Page:

    <head runat="server"> <title></title> <script src="Scripts/jquery-3.4.1.js"></script> <script> //Month and Date format function format(num) { if (num < 10) return "0" + num; else return num; } $(document).ready(function () { $("#chooseDate").change(function () { var checkDate = new Date($(this).val()); //get Date format "MM-dd" var m_d = format((checkDate.getMonth() + 1)) + "-" + format(checkDate.getDate()); $("#MonthAndDate").val(m_d); //compare with 3 ranges $("#CheckDate").click(); }); }); </script> </head> <body> <form id="Form" runat="server"> <div> <asp:TextBox ID="MonthAndDate" runat="server" Hidden="hidden"></asp:TextBox> <asp:Button ID="CheckDate" OnClick="CheckDate_Click" runat="server" Hidden="hidden"/> Choose Date: <input type="date" id="chooseDate"/><br /><br /> Filter in: <asp:TextBox ID="FieldValue" runat="server"></asp:TextBox> </div> </form> </body>
    Code behind:
    
    protected void CheckDate_Click(object sender, EventArgs e)
            {
                String Month_Date = MonthAndDate.Text.ToString();
                if (String.Compare(Month_Date, "03-16") > 0 && String.Compare(Month_Date, "03-23") < 0)
                {
                    FieldValue.Text = "A";
                }
                else if (String.Compare(Month_Date, "03-24") > 0 && String.Compare(Month_Date, "05-30") < 0)
                {
                    FieldValue.Text = "B";
                }
                else if (String.Compare(Month_Date, "06-01") > 0 && String.Compare(Month_Date, "06-15") < 0) {
                    FieldValue.Text = "C";
                }
            }

    Result:

    Hope this can help you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 15, 2020 8:45 AM