# Compare data with "today"

**URL:** https://discourse.nodered.org/t/compare-data-with-today/42866
**Category:** General
**Created:** [19 March 2021 10:16 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866 "2021-03-19T10:16:49Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)
#### Post date: [19 March 2021 10:16 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/1 "2021-03-19T10:16:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 March 2021 10:31 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/2 "2021-03-19T10:31:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)
#### Post date: [19 March 2021 10:51 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/3 "2021-03-19T10:51:47Z")

</div>

Thats how i get the data:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/667f4db56bd3400280aff8f33bed93360fded189.png)

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

---

<div class="post-metadata">

### Author: ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)
#### Post date: [19 March 2021 11:23 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/4 "2021-03-19T11:23:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 March 2021 11:34 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/5 "2021-03-19T11:34:58Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)

---

<div class="post-metadata">

### Author: ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)
#### Post date: [19 March 2021 11:50 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/6 "2021-03-19T11:50:04Z")

</div>

perfect. thanks 🙂

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [2 April 2021 11:50 UTC](https://discourse.nodered.org/t/compare-data-with-today/42866/7 "2021-04-02T11:50:23Z")

</div>

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