Is there a simple way to add these two time strings and get a new time result . Or if easier two objects from Date and Time. Thank you

1:30:00
1:35:00
Is there a simple way to add these two times strings and get a new time which should be something 3:05:00?

Is there a simple way to amend this function to subtract these two time strings and get a new time result .I have looked at the add function which works great and the link which is helpful but not got it working to subtract also. Thank you.

You can do a search on the Internet to see how to manipulate dates and times with Javascript. For example, see this link .

Here’s a simple solution for time strings that I got searching the Internet:

$w.onReady(function () {
   let times = ['01:30:00', '01:35:00'];
   let result = addTimes(times);
   console.log(result);
});

function addTimes(times = []) {
   const z = (n) => (n < 10 ? '0' : '') + n;

   let hour = 0
   let minute = 0
   let second = 0
   for (const time of times) {
      const splited = time.split(':');
      hour += parseInt(splited[0]);
      minute += parseInt(splited[1])
      second += parseInt(splited[2])
   }
   const seconds = second % 60
   const minutes = parseInt(minute % 60) + parseInt(second / 60)
   const hours = hour + parseInt(minute / 60)

   return z(hours) + ':' + z(minutes) + ':' + z(seconds)
}

For Date objects, you can convert each Date object to milliseconds using the getTime() function, add the two times, and then display.

Thank you for the example and the link. I did try to find this on the net however there seemed little information. This is most helpful and shames my attempt to solve the problem. I do appreciate your help and guidance very much.

Is there a simple way to amend this function to subtract these two time strings and get a new time result .I have looked at the add function which works great and the link which is helpful but not got it working to subtract also. Thank you.

@coz An Internet search will turn up a number of different possibilities. Here is a link to a thread with a discussion of several different methods.

I would suggest visiting the following sites for information on programming in Javascript:

@yisrael-wix Thank you

0