Times past midnight

2 posts, 1 answers
  1. Sean
    Sean avatar
    19 posts
    Member since:
    Jun 2012

    Posted 23 May 2014 Link to this post

    Hey all,

    I have a time picker control that allows me to pick a time from a set of business hours. Normally, those hours run from around 9AM until (at the latest) 10PM. Since the times appear within the same day, there is no problem. Occasionally, however, our business hours go until around 3AM. 

    I can set the min/max times well enough. The control renders the time blocks (every 30 minutes) appropriately, but I cannot select or enter any time past midnight (Even though the times are rendered in the control). I can validate that the selected time falls between the established min/max date-time during the OnSelecting event but it still throws an error and prevents the time from being selected.

    How do i get around this? This is a pretty significant business need for us, and i would hate to have to render the control based upon what the current time is, especially since our business folks may have to go back and enter data retroactively.


    Sean Williams
    Software Developer
    Seaworld Parks & Entertainment
  2. Answer
    Angel Petrov
    Angel Petrov avatar
    1044 posts

    Posted 27 May 2014 Link to this post

    Hi Sean,

    If the targeted functionality is to select only the time and not the date you can remove the min and max times thus allowing the user to select any time from the listed ones.

    <telerik:RadTimePicker ID="RadTimePicker3"  runat="server">
            <asp:Button Text="Get selected Time" OnClick="Unnamed_Click" runat="server" />
            <asp:Label ID="TimeLabel" runat="server"></asp:Label>

    protected override void OnInit(EventArgs e)
            DateTime[] dtArray = new DateTime[34];
            int initialMinutes=570;
            for (int hour = 0; hour < 34; hour++)
                dtArray[hour] = DateTime.UtcNow.Date.AddMinutes(initialMinutes);
                initialMinutes += 30;
            RadTimePicker3.TimeView.CustomTimeValues = dtArray;
        protected void Unnamed_Click(object sender, EventArgs e)
            TimeLabel.Text = RadTimePicker3.SelectedTime.ToString();

    If however you want to also get a reference to the date you should manually add one day on the server when a time past midnight and before 9:30 AM is selected.

    Angel Petrov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top