Hello, I’m new to coding, and I’m stuck when trying to find the time difference (between the current time and the userinput in a time picker). Specifically, I want when a user changes the time in a time picker, the difference in hours between the time chosen and the current time to be displayed in an input box. I’ve tried different code variations, but I don’t know what I’m doing wrong. I would really appreciate some guidance in the right direction.
N/B- the time picker is set to display the current time in 24hr format.
Below is a code snippet that, of course, is not working.
$w.onReady(() =>{
$w("#timePicker1").onChange(() =>{
var today= new Date();
let inputtime = $w("#timePicker1").value;//Value from time picker
let timeDiff = inputtime.getTime()-today.getTime()
let timeDiffhrs = timeDiff/3600000
$w("#input3").value = timeDiffhrs
I have worked out the code below but now its resulting to a ‘NaN’ error. Would you help me identify the source of the error or why the code is not working?
$w.onReady(() =>{
$w("#timePicker1").onChange(() =>{
var today= new Date();
let inputtime = $w("#timePicker1").value;//Value from time picker
$w("#input3").value =`${Number(inputtime.getHour -String(today.getHour))} hrs left`
});
})