locked
check ddlTimefrom and ddlTimeTo in between 13:00 to 14:00 RRS feed

  • Question

  • User-807418713 posted

    Hello

    I'm using this in my old asp.net 2.0 C# page

     private void BindTime()
        {
            // Set the start time (00:00 means 12:00 AM)
            DateTime StartTime = DateTime.ParseExact("00:00", "HH:mm", null);
            // Set the end time (23:55 means 11:55 PM)
            DateTime EndTime = DateTime.ParseExact("23:55", "HH:mm", null);
            //Set 5 minutes interval
            TimeSpan Interval = new TimeSpan(0, 30, 0);
            //To set 1 hour interval
            //TimeSpan Interval = new TimeSpan(1, 0, 0);           
            ddlTimeFrom.Items.Clear();
            ddlTimeTo.Items.Clear();
            while (StartTime <= EndTime)
            {
                //ddlTimeFrom.Items.Add(StartTime.ToShortTimeString());
                //ddlTimeTo.Items.Add(StartTime.ToShortTimeString());
                ddlTimeFrom.Items.Add(StartTime.ToString("HH:mm"));
                ddlTimeTo.Items.Add(StartTime.ToString("HH:mm"));
                StartTime = StartTime.Add(Interval);
                
            }
            ddlTimeFrom.Items.Insert(0, new ListItem("--Select--", "0"));
            ddlTimeTo.Items.Insert(0, new ListItem("--Select--", "0"));
        }
    
    



    I want to show alert for example

    If ddltimefrom i select 09:00 and in ddltimeto i select 14:05 then i want to show alert " your time range is in lunch time"

    If ddltimefrom i select 09:00 and in ddltimeto i select 11:30 then no alert

    If ddltimefrom i select 12:00 and in ddltimeto i select 13:30 then i want to show alert " your time range is in lunch time"

    If ddltimefrom i select 13:00 and in ddltimeto i select 16:35 then i want to show alert " your time range is in lunch time"

    Thanking You

    Wednesday, April 21, 2021 11:38 PM

Answers

  • User1535942433 posted

    Hi Gopi.MCA,

    According to your description,I'm guessing that when the from time and to time includes 13:00-14:00, it will alert the message.

    You could refer to below this:

           <div>
                TimeFrom: <asp:DropDownList ID="ddlTimeFrom" runat="server" ></asp:DropDownList>
                TimeTo:<asp:DropDownList ID="ddlTimeTo" runat="server"></asp:DropDownList>
            </div>
            <asp:Button ID="btn1" runat="server" OnClick="btn1_Click" Text="Check" />

    Code-behind:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindTime();
                }
            }
            private void BindTime()
            {
                // Set the start time (00:00 means 12:00 AM)
                DateTime StartTime = DateTime.ParseExact("00:00", "HH:mm", null);
                // Set the end time (23:55 means 11:55 PM)
                DateTime EndTime = DateTime.ParseExact("23:55", "HH:mm", null);
                //Set 5 minutes interval
                TimeSpan Interval = new TimeSpan(0, 30, 0);
                //To set 1 hour interval
                //TimeSpan Interval = new TimeSpan(1, 0, 0);           
                ddlTimeFrom.Items.Clear();
                ddlTimeTo.Items.Clear();
                while (StartTime <= EndTime)
                {
                    //ddlTimeFrom.Items.Add(StartTime.ToShortTimeString());
                    //ddlTimeTo.Items.Add(StartTime.ToShortTimeString());
                    ddlTimeFrom.Items.Add(StartTime.ToString("HH:mm"));
                    ddlTimeTo.Items.Add(StartTime.ToString("HH:mm"));
                    StartTime = StartTime.Add(Interval);
    
                }
                ddlTimeFrom.Items.Insert(0, new ListItem("--Select--", "0"));
                ddlTimeTo.Items.Insert(0, new ListItem("--Select--", "0"));
            }
    
            protected void btn1_Click(object sender, EventArgs e)
            {
                DateTime x = Convert.ToDateTime(ddlTimeFrom.SelectedItem.Value);
                DateTime y = Convert.ToDateTime(ddlTimeTo.SelectedItem.Value);
                if (x.Hour<y.Hour)
                {
                    if (x.Hour <= 13 && y.Hour > 13)
                    {
                        string script = "<script type=\"text/javascript\">alert('your time range is in lunch time');</script>";
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script);
                    }
                }
            }

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 22, 2021 8:50 AM
  • User-1716253493 posted
    if(timefrom<=lunchend && timeto>=lunchstart)
    {
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 23, 2021 4:29 PM

All replies

  • User1535942433 posted

    Hi Gopi.MCA,

    I want to show alert for example

    If ddltimefrom i select 09:00 and in ddltimeto i select 14:05 then i want to show alert " your time range is in lunch time"

    If ddltimefrom i select 09:00 and in ddltimeto i select 11:30 then no alert

    If ddltimefrom i select 12:00 and in ddltimeto i select 13:30 then i want to show alert " your time range is in lunch time"

    If ddltimefrom i select 13:00 and in ddltimeto i select 16:35 then i want to show alert " your time range is in lunch time"

    What's the condition to check and alert " your time range is in lunch time"?

    I suggest you could use this to alert with button click.

    Page.ClientScript.RegisterStartupScript(Page, Page.GetType(), "MessageThenRedirect", "alert('your time range is in lunch time');window.location='" +
    "../xxx/xxx" + ".aspx';", true);

    Best regards,

    Yijing Sun

    Thursday, April 22, 2021 5:16 AM
  • User-807418713 posted

    Hello

    I have two dropdownlist That Is ddlltimefrom and ddltimeto our employee lunch time is 13:00 to 14:00

    I want to check is ddltimefrom and ddltimeto has the value or not in in if condition..?

    if that value available then i want to show alert your time range is in lunch time

    else no alert

    Thanking you  

    Thursday, April 22, 2021 6:04 AM
  • User1535942433 posted

    Hi Gopi.MCA,

    According to your description,I'm guessing that when the from time and to time includes 13:00-14:00, it will alert the message.

    You could refer to below this:

           <div>
                TimeFrom: <asp:DropDownList ID="ddlTimeFrom" runat="server" ></asp:DropDownList>
                TimeTo:<asp:DropDownList ID="ddlTimeTo" runat="server"></asp:DropDownList>
            </div>
            <asp:Button ID="btn1" runat="server" OnClick="btn1_Click" Text="Check" />

    Code-behind:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindTime();
                }
            }
            private void BindTime()
            {
                // Set the start time (00:00 means 12:00 AM)
                DateTime StartTime = DateTime.ParseExact("00:00", "HH:mm", null);
                // Set the end time (23:55 means 11:55 PM)
                DateTime EndTime = DateTime.ParseExact("23:55", "HH:mm", null);
                //Set 5 minutes interval
                TimeSpan Interval = new TimeSpan(0, 30, 0);
                //To set 1 hour interval
                //TimeSpan Interval = new TimeSpan(1, 0, 0);           
                ddlTimeFrom.Items.Clear();
                ddlTimeTo.Items.Clear();
                while (StartTime <= EndTime)
                {
                    //ddlTimeFrom.Items.Add(StartTime.ToShortTimeString());
                    //ddlTimeTo.Items.Add(StartTime.ToShortTimeString());
                    ddlTimeFrom.Items.Add(StartTime.ToString("HH:mm"));
                    ddlTimeTo.Items.Add(StartTime.ToString("HH:mm"));
                    StartTime = StartTime.Add(Interval);
    
                }
                ddlTimeFrom.Items.Insert(0, new ListItem("--Select--", "0"));
                ddlTimeTo.Items.Insert(0, new ListItem("--Select--", "0"));
            }
    
            protected void btn1_Click(object sender, EventArgs e)
            {
                DateTime x = Convert.ToDateTime(ddlTimeFrom.SelectedItem.Value);
                DateTime y = Convert.ToDateTime(ddlTimeTo.SelectedItem.Value);
                if (x.Hour<y.Hour)
                {
                    if (x.Hour <= 13 && y.Hour > 13)
                    {
                        string script = "<script type=\"text/javascript\">alert('your time range is in lunch time');</script>";
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script);
                    }
                }
            }

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 22, 2021 8:50 AM
  • User-1716253493 posted
    if(timefrom<=lunchend && timeto>=lunchstart)
    {
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 23, 2021 4:29 PM