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

Template to show total hours in MVVM

1 Answer 103 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 2
Eric asked on 30 Sep 2014, 06:04 PM
In my scheduler, I have, as a part of the definition:

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

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?

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 01 Oct 2014, 10:18 AM
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) #

Regards,
Vladimir Iliev
Telerik
 

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.

 
Tags
Scheduler
Asked by
Eric
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Share this question
or