Hello, I'd like to combine the input from separate date and time pickers in a form into one column in my database.
Ive looked through the forum and come across several examples that I am trying to build off of, basically breaking the date and time inputs down to their constituent parts, then building back up to a javascript element in milliseconds to pass on to the database with set field values.
// deconstruct date and time
$w.onReady(function () {
let Y = ($w("#textDate").value.getFullYear()-1970)*31556952000;
let M = $w("#textDate").value.getMonth()*2592000000;
let D = ($w("#textDate").value.getDate()-1)*86400000;
let hour = ($w("#textTime").value.slice(0, 2)-3)*3600000;
let min = $w("#textTime").value.slice(3, 5)*60000;
let datetime = new Date(Y+M+D+hour+min);
console.log(datetime)
$w("meetingNotesWrite").setFieldValue("dateTime", datetime);
});
This seems to work in the console log but the database doesnt pick up anything at all (the code for the submit button is elsewhere in the code but is working for other fields.
Any insight?
Hi Melissa,
You're retrieving the datetime values in the onReady() function, This means the values are retrieved once the page loads which is why the console shows the default values - today's date.
In order to retrieve the values upon change you need to use the onChange() event handler for each of the elements (date picker and time picker).
you can see more info here:
https://www.wix.com/corvid/reference/$w.DatePicker.html#onChange