Good day, I need to get the number of days between two dates entered into two kendo.DateTimePickers.
My solution always ends with NaN value. RentStartDate and RentEndDate are stored in db as DateTime.
Thank you for your advice.
<script>$("#RentEndDate").change(function () {
var startDate = kendo.toString($("#RentStartDate").data("kendoDateTimePicker").value(), "dd.MM.yyyy");
var endDate = kendo.toString($("#RentEndDate").data("kendoDateTimePicker").value(), "dd.MM.yyyy");
alert(calculate(startDate, endDate));
});
function calculate(first, second) {
var diff = Math.round((second - first) / 1000 / 60 / 60 / 24);
return diff;
}
CreateOrders.cshtml
<h4>Termín půjčení</h4>
<div class="t-col t-col-6 t-col-xs-12 t-col-sm-12 t-col-md-12 col-sm-6">
<label for="rentStartPicker">Půjčit od</label>
@(Html.Kendo().DatePickerFor(model => model.RentStartDate).Name("rentStartPicker").HtmlAttributes(new { style = "height:28px;", required = "required", validationmessage = "Vyberte datum" }))
</div>
<div class="t-col t-col-6 t-col-xs-12 t-col-sm-12 t-col-md-12 col-sm-6">
<label for="rentEndPicker">Půjčit do</label>
@(Html.Kendo().DatePickerFor(model => model.RentEndDate).Name("rentEndPicker").HtmlAttributes(new { style = "height:28px;", required = "required", validationmessage = "Vyberte datum" }))
</div>
Try using Moment.js to convert the values from the date pickers into date objects. That will solve your problems.
Something like...
var startDate = moment($("#RentStartDate").data("kendoDateTimePicker").value());
I actually recommend using Moment.js for pretty much any time you're manipulating dates, especially when those dates come from web page elements. Kendo is pretty good, but I've had issues trying to use the dates directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With