Template to show total hours in MVVM

2 posts, 0 answers
  1. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2014

    Posted 30 Sep 2014 Link to this post

    In my scheduler, I have, as a part of the definition:

           "<p>" +
           "#= kendo.toString(start, 'MMM dd yyyy hh:mm t') # (#= kendo.toString(new Date(end.getTime()-start.getTime()).getHours()) #) #= title#" +

    then this runs, I get 

    <p>Sep 29 2014 12:00 t (20) Smith, John</p>

    20 hours is the value I get for a one hour meeting.
    21 hours is the value I get for a two hour meeting.

    I would have expected 1 and 2 hours, respectively...

    How do I properly calculate total hours between two DateTime values in javascript MVVM?

  2. Vladimir Iliev
    Vladimir Iliev avatar
    2206 posts

    Posted 01 Oct 2014 Link to this post

    Hi Robert,

    Instead of creating new Date object I would suggest to divide the result by the milliseconds per hour as demonstrated below:

    #= Math.round((end.getTime() - start.getTime()) / kendo.date.MS_PER_HOUR) #

    Vladimir Iliev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top