Hi
Just wanted to know the code on how to find the difference in days and storing it in a input field.
For example, From Date and To Date(OnBlur) the variable should be the difference between the two dates and storing in the Input field
Please help me out
Grab the datepicker's value (which is a Date object), use getTime() to get value in epoch time and subtract.
let date1 = $w("#datePicker1").value let date2 = $w("#datePicker2").value let timeDiff = date2.getTime() - date1.getTime()
this gives you the diff in milliseconds.
now if you want to convert to days for example, just divide the value you got in ms:
let diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
Did you get this working yet? I need to do the same thing...
Hello! The example code in this thread looks pretty straight forward, but my 1st line (Line 6) of code returns a "null" instead of a date value.
3 $w.onReady(function () { 4 //TODO: write your page related code here... 5 6 let purchDate = $w("#datePicker2").value; 7 let todaysDate = new Date(); 8 9 let timeDiff = purchDate.getTime() + todaysDate.getTime(); 10 11 let timeConv = Math.ceil(timeDiff / (1000*3600*24)); 12 13 console.log (purchDate)
I must be missing something.!? Does someone have an idea?
It worked perfect. Thanks Chief
Thanks Chief. Let me try