I need some help combining two columns of data into one.
Column A: a Cell contains 3 time values like 9:00, 10:00, 11:00.
Column B: Contains date values like 02/03/24.
I want to combine them so the result looks like this: 02/03/24 9:00, 02/03/24 10:00, 02/03/24 11:00.
What’s the best way to achieve this? Any guidance would be greatly appreciated!
Thanks in advance!
If it’s purely for displaying purposes, you can do it like this.
Thanks for the reply, Sorry i didnt write it properly, i actually have all the value within the same cell for time. with template that would only give me
02/03/24 9:00, 10:00, 11:00 within a cell instead of 02/03/24 9:00, 02/03/24 10:00, 02/03/24 11:00.
any other ways that i can create that result?
Use a JavaScript column:
const times = p2.split(', ');
const arr = [];
while (times.length>0) {
const time = times.shift();
arr.push(`${p1} ${time}`);
}
return arr.join(', ');
NB: Obviously, you should pass your actual column values as p1
& p2
, rather than hardcoding them. Also, I spent about 2 minutes on that JavaScript, I’m sure it could be improved
Here another JS code to confirm that many times we can find the same solution using several ways in Glide:
let time=p2.split(", ");
let newList ="";
for (let i = 0; i < time.length; i++) {
newList += `${p1} ${time[i]},`
}
return newList.slice(0, -1)
but I have to recognize that using the join() method with an array
return arr.join(', ');
is a more elegant solution than my .slice(0, -1)
trick to delete the last comma (,) in the result
Thanks for the reminder @Darren_Murphy
thank you very much for the help!
hehe I knew it would be possible as a one liner using map, but I was too lazy to figure it out