# Get minutes between current time and 15:00

I'm almost getting this solved by muddling my way through lots of searches, but not quite.

I want to get the current time (probably from an Inject) then check how many minutes it is until 15:00.
eg. 15:00 - timestamp = xx minutes
As usual there seem to be almost infinite ways of doing this and I suspect I've got myself confused.

One of my problems is I don't quite understand how to specify "15:00" in Epoch time. It seems like I have to set an epoch time to some specific date & time, then extract the hours:minutes?

I'd prefer to not to use a Function node. A Change node and JSONATA would be fine because I'm trying to learn JSONATA at present.
Also happy to use some other set of nodes if there's a simpler way to do it.

To give context, I know the approximate rate at which my hot water heats on boost. I want to check the temperature of the water, then calculate when to turn on boost so it reaches (approximately) my set-point temperature by 15:00 each day. This will give the maximum time for solar to heat the water during the day, but if the day is cloudy it will ensure the water is hot before we go to peak electricity rate at 15:00.

I'm sure this has been answered before, but I just can't find the right topic that I can follow and tweak to my usage, obviously searching the wrong terms.

Thanks.

In a change node
set
`msg.` `payload`
to value of
`J:` `\$moment("15:00", "HH:mm").diff(\$moment(),"minutes")`
Which should output the minutes between now and 15:00.
Using Just JSONata time functions
`(\$toMillis(\$substringBefore(\$now(),"T") & "T" & "15:00:00") - \$millis()) / 60000`

Thank you @E1cid, that got me on the right track at last.
I ended up with

``````(
"ontime" & ' ' & \$moment(\$OnTimeDate).format('HH:mm')
)
``````

I seemed to have to move values to variables to make it all work. A nice learning exercise.

this works like a charm... giving minutes and even days till target .. just put into function node and provide target date/time in msg.payload

return msg;

function dateToHowManyAgo(stringDate) {
var currDate = new Date();
var diffMs = currDate.getTime() - new Date(stringDate).getTime();
var sec = diffMs / 1000;
if (sec < 60)
return parseInt(sec) + ' second' + (parseInt(sec) > 1 ? 's' : '') + ' ago';
var min = sec / 60;
if (min < 60)
return parseInt(min) + ' minute' + (parseInt(min) > 1 ? 's' : '') + ' ago';
var h = min / 60;
if (h < 24)
return parseInt(h) + ' hour' + (parseInt(h) > 1 ? 's' : '') + ' ago';
var d = h / 24;
if (d < 30)
return parseInt(d) + ' day' + (parseInt(d) > 1 ? 's' : '') + ' ago';
var m = d / 30;
if (m < 12)
return parseInt(m) + ' month' + (parseInt(m) > 1 ? 's' : '') + ' ago';
var y = m / 12;
return parseInt(y) + ' year' + (parseInt(y) > 1 ? 's' : '') + ' ago';
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.