none
Time in time out custom validation help

    Question

  • I have two fields

    Time In

    Time Out

     

    I have a validation control that compares the two and if time out is less than time in then if gives an error. Unfortunately it’s not taking into account AM and PM. For instance if Time In = 11:35AM and Time Out = 11:30PM my validator will read it as being less than. How can I set it up to account for AM and PM?

     

     

    <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Time in cannot be less than time out." ControlToCompare="ddlTimeFrom" ControlToValidate="ddlTimeTo" Operator="GreaterThan"></asp:CompareValidator>

     

    Thanks.

    Saturday, April 23, 2016 12:43 AM

Answers

  • I was able to get this figured out in the ASP.NET forum. I changed the time dropdowns to military time and the validator below worked.

    <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Time in cannot be less than time out." ControlToCompare="ddlTimeFrom" ControlToValidate="ddlTimeTo" Operator="GreaterThan"></asp:CompareValidator>

    Solution

    Thanks!!

    • Proposed as answer by lake XiaoModerator Wednesday, April 27, 2016 12:46 AM
    • Marked as answer by kawi6rr Wednesday, April 27, 2016 5:36 PM
    Tuesday, April 26, 2016 8:59 PM

All replies

  • Try adding an attribute: Type = "Date".

    Saturday, April 23, 2016 2:26 PM
  • Unfortunately that didn't work, I'm surprised VS doesn't make this type of validation easier.
    Monday, April 25, 2016 6:51 PM
  • Hi Kawi6rr,

    Since your problem is more related to the ASP.NET. I suggest you'd better post this issue to the ASP.NET forum for better support.

    https://forums.asp.net/

    Thanks for your understanding.

    Best Regards,

    Lake  Xiao

    Tuesday, April 26, 2016 12:50 AM
    Moderator
  • I was able to get this figured out in the ASP.NET forum. I changed the time dropdowns to military time and the validator below worked.

    <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Time in cannot be less than time out." ControlToCompare="ddlTimeFrom" ControlToValidate="ddlTimeTo" Operator="GreaterThan"></asp:CompareValidator>

    Solution

    Thanks!!

    • Proposed as answer by lake XiaoModerator Wednesday, April 27, 2016 12:46 AM
    • Marked as answer by kawi6rr Wednesday, April 27, 2016 5:36 PM
    Tuesday, April 26, 2016 8:59 PM
  • Hi kawi6rr,

    Thanks for sharing the solution here, please mark your reply as answer so that I could close this case.

    Have a nice day.

    Best Regards,

    Lake Xiao

    Wednesday, April 27, 2016 12:47 AM
    Moderator