This is a migrated thread and some comments may be shown as answers.

Times past midnight

1 Answer 57 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 23 May 2014, 01:24 PM
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.

Help?

Sean Williams
Software Developer
Seaworld Parks & Entertainment

1 Answer, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 27 May 2014, 11:25 AM
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.

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

C#:
protected override void OnInit(EventArgs e)
    {
        base.OnInit(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.

Regards,
Angel Petrov
Telerik
 

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.

 
Tags
Calendar
Asked by
Sean
Top achievements
Rank 2
Answers by
Angel Petrov
Telerik team
Share this question
or