how to add two duration

Hi Expert,

I had manage to poplute the duration for all my tasak ticket. now I'm trying to sum up the total duration taken by all the task, please advice how to do it?

I'm using 

date1 = Math.floor( (new Date( starttime ).getTime()) /1000);
date2 = Math.floor((new Date( endtime ).getTime())/1000);
duration = system.functions.val((date2- date1), 3);

which return me value of dd hh:mm:ss

now I need to sum all these together but when I try system.functions.val(duration,1) it a null value