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

RadTimePicker add hours with client side api

3 Answers 147 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 12 Jan 2012, 05:16 PM
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 :)

3 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 16 Jan 2012, 03:02 PM
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!
0
Jacob
Top achievements
Rank 1
answered on 18 Jan 2012, 05:21 PM
function radStartTime_OnDateSelected(pickerInstance, args)
{
     var radStartTimePicker = $find('<%= radStartTime.ClientID%>');
     var radEndTimePicker = $find('<%= radEndTime.ClientID%>');
     radEndTimePicker.set_selectedDate(radStartTimePicker.get_selectedDate());
}
0
Vasil
Telerik team
answered on 20 Jan 2012, 08:38 AM
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
Tags
Calendar
Asked by
Jacob
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Jacob
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or