I have 2 input fields; 1 for dates and for for a time.
The input for (multiple) dates generates a string like: 2021-05-01,2021-05-02,2021-05-03.
If there is set a time in the time input (e.g. 10:00) field, the dates string above should look like this: 2021-05-01T10:00,2021-05-02T10:00,2021-05-03T10:00.
To generate this, i do the following: first check if time input has value.
If so, grab all the date values, put a T after them and create a new comma separated string.
But i do not know how to put a , between the date-time values
var startdateMulti = $('.add-startdate').val(); // grab input value
var starttime = $('.add-starttime').val(); // starttime Multi
var startdateMultiArr = startdateMulti.split(',');
for(var i = 0; i < startdateMultiArr.length; i++) {
startdateMultiArr[i] = startdateMultiArr[i].replace(/^\s*/, "").replace(/\s*$/, ""); // Trim the excess whitespace.
if(starttime) { // if there is a starttime filled in
start += startdateMultiArr[i] + 'T' + starttime;
}
else {
start += startdateMultiArr[i];
}
}
console.log(start);
If time has filled in, console.log(start) generates something like:
2021-05-01T10:002021-05-02T10:002021-05-03T10:00 and it should be 2021-05-01T10:00,2021-05-02T10:00,2021-05-03T10:00
How can i achieve this?