Hello!
So I'm calculating time between two payloads to display in a nice readable format in a function node.
"X Days and X Hours"
It's not quite working as anticipated.
The read out of Days is incorrect. It calculates a whole Day after the 12th hour between timestamps. I'd like this to not happen till after the 24th hour.
The time I am comparing is between now and the past... ie days and hours ago...
Can anyone help fix this?
let current = new Date(msg.currentTime).valueOf();
let previous = new Date(msg.previousTime).valueOf();
let diff = current - previous;
let mins = Math.round((diff % 3600000) / 60000);
let hours = Math.floor(diff / 3600000)
let days = Math.round((current - previous) / (1000 * 60 * 60 * 24))
msg.calculatedInfo = days + " Days and " + hours % 24 + " Hours.";
return msg;
Thanks in advance!