Saya menyimpan dua tanggal di dalam var (dibuat oleh pemilih tanggal). Untuk memformatnya saya menggunakan moments.js
Saya ingin menghitung jumlah hari antara dua bidang ini dan menyimpan nomor ini di dalam var days
. Ini kode saya sejauh ini:
// When someone clicks my submit button, I create an url stored in the var url.
$(".book_submit").on('click', function(e){
// I get the datepicker and input fields data
var from = $('.from').val();
var to = $('.to').val();
// I can format the "from" var the way I want
from = moment(from, "DD.MM.YYYY");
from = moment(from).format("YYYY-MM-DD");
// I can format the "to" var the way I want
to = moment(to, "DD.MM.YYYY");
to = moment(to).format("YYYY-MM-DD");
// I want to store the number between the two dates in the var "days", to place it inside my link below. I have found ".diff(to, 'days') in the moments documentation.
//days = from.diff(to, 'days'); // =1
var url = "https://mycustomlink&days= " + days + "";
});
Saya tidak bisa membuat from.diff(to, 'days')
berfungsi dan menyimpannya di dalam variabel. Saya telah mencoba mengaturnya seperti:
var days = from.diff(to, 'days');
Bagaimana saya bisa menyimpan perbedaan antara hari-hari ini di dalam var days
saya? Saya menghargai saran apa pun.