Hello,
I need to subtract to time values with this format:
Time 1: HH:mm:ss
08:00:00
Time 2: HH:mm:ss
08:15:00
I need to get the duration (Time 2 - Time 1 | 08:00:00 - 08:15:00) in the following format:
0.250
Can anybody point me in the right direction?
Thank you very much for all your help.
@streczz how about so?
var timeStart = '08:00:00'
var datetimeStart = new Date('1970-01-01T' + timeStart + 'Z')
var start = Date.parse(datetimeStart)
var timeStop = '08:15:00'
var datetimeStop = new Date('1970-01-01T' + timeStop + 'Z')
var stop = Date.parse(datetimeStop)
var duration = (stop - start) / 3600000
return [{ json: {duration: duration}}];
Maybe there’s an easier, more direct way of doing this, but this is what I can think of right now with my limited knowledge of JavaScript combined with my ‘calculation logic’ that I would use in FileMaker
1 Like
{{ new Date(new Date().getTime()-(7*24*60*60*1000)).toISOString() }}
takes 7 days away from today
just change the 7 to whatever
or change the - to a +
EDIT: ignore me, didn’t read your question properly, lol
1 Like
Inspired by @RedPacketSec … there are many solutions to the same challenge … for example:
let start2 = (timeStart.split(':')[0] * 3600) + (timeStart.split(':')[1] * 60) + (timeStart.split(':')[2])
let stop2 = (timeStop.split(':')[0] * 3600) + (timeStop.split(':')[1] * 60) + (timeStop.split(':')[2])
let duration2 = (stop2 - start2) / 360000
And I would really love to see more, and probably more elegant, solutions. Helps me to learn JavaScript to ‘calculate’ text …