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

Date Difference between Multiple DatePickers

3 Answers 1441 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Cyndie
Top achievements
Rank 1
Cyndie asked on 16 Feb 2012, 04:35 PM
I have two DatePickers; one for a start date and one for an end date.  What would be the best way to calculate the number of days between them? 

3 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 17 Feb 2012, 10:43 AM
Hi Cyndie,

KendoUI does not have a build-in method for calculating difference between two dates. It is possible to retrieve the selected dates by the value method of the DatePicker and do the calculations via JavaScript. For example:
var startDate = $("#startDate").data("kendoDatePicker").value();
var endDate = $("#endDate").data("kendoDatePicker").value();
 
var diff = Math.round((endDate - startDate)/1000/60/60/24); //Difference in days

In the attachments you can find a sample page where you could see this approach in action.


Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mosh
Top achievements
Rank 1
answered on 27 Mar 2017, 09:09 PM

that does not work will when daylight savings time come into play

0
Boyan Dimitrov
Telerik team
answered on 30 Mar 2017, 02:27 PM

Hello Mosh,

I guess same result will happen if we calculate the difference between two simple JavaScript Date objects. What the value method of the DatePicker does is simply to return a JavaScript Date object. 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Date/Time Pickers
Asked by
Cyndie
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Mosh
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or