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

how set the calendar hours

1 Answer 51 Views
TimePicker
This is a migrated thread and some comments may be shown as answers.
hayula
Top achievements
Rank 1
hayula asked on 04 Nov 2009, 08:27 AM

Hi,

I set the “SelectableDateStart” property to be now,

After I open the calendar the hours are not on the hour

Im expect that the start hour in the calendar will be the next hour that is valid
is it possiable?
thanks,

1 Answer, 1 is accepted

Sort by
0
Accepted
Teodor
Telerik team
answered on 05 Nov 2009, 04:12 PM
Hi hayula,

Thank you for contacting us.

You can use the following helper class with DateTime extension methods:

public static class DateTimeExtensions
    {
        public static DateTime Round(this DateTime date, TimeSpan span)
        {
            long ticks = (date.Ticks / span.Ticks) + (span.Ticks / 2) + 1;
            return new DateTime(ticks * span.Ticks);
        }
        public static DateTime Floor(this DateTime date, TimeSpan span)
        {
            long ticks = (date.Ticks / span.Ticks);
            return new DateTime(ticks * span.Ticks);
        }
        public static DateTime Ceil(this DateTime date, TimeSpan span)
        {
            long ticks = (date.Ticks + span.Ticks - 1) / span.Ticks;
            return new DateTime(ticks * span.Ticks);
        }
    }

... and to get the first time value bigger than the DateTime.Now.TimeOfDay should be set to the SelectedTime property of your TimePicker like:

this.timePicker.SelectedTime = DateTime.Now.Ceil(TimeSpan.FromHours(1)).TimeOfDay;

Hope this will help. Should you need more support get in touch with us. 

Regards,
Teodor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TimePicker
Asked by
hayula
Top achievements
Rank 1
Answers by
Teodor
Telerik team
Share this question
or