Compare data with "today"

Hey i get data from a server {236 entries (objects)}.
68 btw 69 of them update. the others are just older.
now i want to make a function, where i can compare the the value of timestamp with today.
the timestamp i got is in seconds or milliseconds dunno, or as "LocaleString" (Day.Month.Year, Hours:Minutes:Seconds)
the function should finally just transfer the data where the Day.Month.Year = Today, so older entries should be deleted or not transfered.
how can i do that?
Ps.: I am a newbie in Javascript and i work with node-red

To make sure we understand please feed the data into a Debug node and show us what you are receiving.

Thats how i get the data:
grafik

and now i want to compare "seen" with date (Today) and just work after this with the entries from today.

so every entry from today: 00:00:00 until 23:59:59 should be ok, and i can work with.
from data before i want to delete the objects or not work later with them

That appears to be a millisecond timestamp which makes it fairly easy. You can make a javascript out of that in a Function node using
let timestamp = new Date(msg.payload.seen)
then you can get the current time as a Date object using
let now = new Date()
then if those are on the same day then the day, month and year in the local timezone must be the same. When you say that you want it to be the same day then I presume you mean the same day in local time, not in UTC. So you can do (untested)
if (now.getDay() == timestamp.getDay() && now.getMonth() == timestamp.getMonth() and now.getFullYear() == timestamp.getFullYear()) {

The docs for the Date object are at Date - JavaScript | MDN

perfect. thanks :slight_smile:

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