RadTimePicker add hours with client side api

4 posts, 0 answers
  1. Jacob
    Jacob avatar
    2 posts
    Member since:
    Nov 2011

    Posted 12 Jan 2012 Link to this post

    How do I add hours to the current time on the RadTimePicker control?

    Currently my 'End' RadTimePicker automatically defaults to the 'Start' time RadTimePicker when the user selects the Start time. My desired output is for the End RadTimePicker to automatically default the the Start time RadTimePicker, plus one hour, when the user selects the Start time.

    Thanks for any help :)
  2. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 16 Jan 2012 Link to this post

    Jacob:

    Would it be possible for you to paste your code and a screen shot of your application. This would make it easier to understand your requirement and to help me to assist you.

    Cheers!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jacob
    Jacob avatar
    2 posts
    Member since:
    Nov 2011

    Posted 18 Jan 2012 Link to this post

    function radStartTime_OnDateSelected(pickerInstance, args)
    {
         var radStartTimePicker = $find('<%= radStartTime.ClientID%>');
         var radEndTimePicker = $find('<%= radEndTime.ClientID%>');
         radEndTimePicker.set_selectedDate(radStartTimePicker.get_selectedDate());
    }
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 20 Jan 2012 Link to this post

    Hello Jacob,

    The get_selectedDate is returning a Date JavaScript object so you could use it's functions to manipulate it.
    For example you could use setHours to add one more hour.
    currentDateTime = $find("<%= radStartTime.ClientID%>").get_selectedDate();
    nextDateTime = new Date(currentDateTime);
    nextDateTime.setHours(currentDateTime.getHours() + 1);
    radEndTimePicker.set_selectedDate(nextDateTime);
    Note that you will need additional check if the current hour is 23.

    There are other solutions as well, please check this forum:
    http://stackoverflow.com/questions/1050720/adding-hours-to-javascript-date-object

    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top