Ngày tốt, Tôi cần lấy số ngày giữa hai ngày được nhập vào hai kendo.DateTimePickers.Ngày giữa hai ngày kendo DateTimePicker
Giải pháp của tôi luôn kết thúc bằng giá trị NaN. RentStartDate và RentEndDate được lưu trữ trong db là DateTime.
Cảm ơn lời khuyên của bạn.
<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>
Bạn chuyển đổi giá trị ngày thành chuỗi trước khi tính toán. – Fabio