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

RadDateTimePicker and Timespan on client side

2 Answers 67 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 10 Mar 2010, 06:55 PM
Dear Telerik-Team,

I have two datetimepickers on my webpage. One for a start date and the other one for the end date. Now I want to calculate the timespan between both dates and disply the result in a radtextbox on the client side (so without any postback).

I don't have any idea which javascript methods I should use to achieve this goal, so could you please provide me with a sample? I performed some tests with e.get_newDate().toDateString() but didn't come to a satisfying result.

I a looking forward to hering from you,
Kind regards,
Marco

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 12 Mar 2010, 04:01 PM
Hello Marco,

Please try the following code snippet:
JavaScript
<telerik:RadCodeBlock runat="server">
  <script type="text/javascript">
     function calculate() {
        var stardDate = $find("<%= RadDateTimePickerStart.ClientID %>").get_selectedDate();
        var endDate = $find("<%= RadDateTimePickerEnd.ClientID %>").get_selectedDate();
        var resultInMilisecunds = endDate.valueOf() - stardDate.valueOf();
     $find("<%= RadTextBoxResult.ClientID %>").set_value(resultInMilisecunds);
}
  </script>
</telerik:RadCodeBlock>
ASPX
<telerik:RadDateTimePicker ID="RadDateTimePickerStart" runat="server">
        </telerik:RadDateTimePicker>
        <telerik:RadDateTimePicker ID="RadDateTimePickerEnd" runat="server">
        </telerik:RadDateTimePicker>
        <telerik:RadTextBox ID="RadTextBoxResult" runat="server"></telerik:RadTextBox>
        <asp:Button ID="buttonCalculate" runat="server" Text="calculate" OnClientClick="calculate();return false;" />

I hope this helps.

Best wishes,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marco
Top achievements
Rank 1
answered on 15 Mar 2010, 08:58 AM
Radoslav,

thanks a lot for the small sample!

I will try this now.

Best wishes,
Marco
Tags
Ajax
Asked by
Marco
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Marco
Top achievements
Rank 1
Share this question
or