how set the calendar hours

2 posts, 1 answers
  1. hayula
    hayula avatar
    8 posts
    Member since:
    Apr 2009

    Posted 04 Nov 2009 Link to this post

    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,

  2. Answer
    Teodor
    Admin
    Teodor avatar
    501 posts

    Posted 05 Nov 2009 Link to this post

    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.
  3. DevCraft banner
Back to Top