RadDateTimePicker and Timespan on client side

3 posts, 0 answers
  1. Marco
    Marco avatar
    12 posts
    Member since:
    Nov 2007

    Posted 10 Mar 2010 Link to this post

    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,
  2. Radoslav
    Radoslav avatar
    1566 posts

    Posted 12 Mar 2010 Link to this post

    Hello Marco,

    Please try the following code snippet:
    <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);
    <telerik:RadDateTimePicker ID="RadDateTimePickerStart" runat="server">
            <telerik:RadDateTimePicker ID="RadDateTimePickerEnd" runat="server">
            <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,
    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.
  3. Marco
    Marco avatar
    12 posts
    Member since:
    Nov 2007

    Posted 15 Mar 2010 Link to this post


    thanks a lot for the small sample!

    I will try this now.

    Best wishes,
Back to Top