Convert time

Hi, how do I convert hours, minutes and seconds?
example 08:22:10
to 8 hours 22 minutes 10 seconds

I’ve used Chuck’s solution before

4 Likes

Do try Jeff’s solution out you’ll learn a thing from there (I already have)

Also I made a JS code for this case

function convertTime(p1) {
  p1 = p1.replace(/(AM|PM)$/i, "").trim();

 
  let timeParts = p1.split(":");

  if (timeParts.length === 2) {
    timeParts.push("00");
  }
  
  else if (timeParts.length === 1) {
    timeParts.push("00", "00");
  }


  const [hours, minutes, seconds] = timeParts;

  
  const formattedHours = Number(hours);
  const formattedMinutes = Number(minutes);
  const formattedSeconds = Number(seconds);

  
  const hourLabel = formattedHours === 1 ? "hour" : "hours";
  const minuteLabel = formattedMinutes === 1 ? "minute" : "minutes";
  const secondLabel = formattedSeconds === 1 ? "second" : "seconds";

  
  return `${formattedHours} ${hourLabel} ${formattedMinutes} ${minuteLabel} ${formattedSeconds} ${secondLabel}`;
}

return convertTime(p1);

if this doesn’t work with the date column it needs only a time value, the date columnn doesn’t provide a time only value, so you can pass this to a template column. That said it’s possible to parse the cell and get just the time

3 Likes