# \[solved\] Data compare eMail / date now

**URL:** https://discourse.nodered.org/t/solved-data-compare-email-date-now/44211
**Category:** General
**Created:** [15 April 2021 06:21 UTC](https://discourse.nodered.org/t/solved-data-compare-email-date-now/44211 "2021-04-15T06:21:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![steinerma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinerma/32/37666_2.png) [@steinerma](https://discourse.nodered.org/u/steinerma)
#### Post date: [15 April 2021 06:21 UTC](https://discourse.nodered.org/t/solved-data-compare-email-date-now/44211/1 "2021-04-15T06:21:01Z")

</div>

hi at all,  
I would like to compare two times with each other. One time is from a parsing of an eMail, the other is the current time. If the difference is greater than 20 seconds, a "true" message should be output. I don't have a solution - does anyone of you have an example?

```auto
[{"id":"391c4649.2ff96a","type":"function","z":"baa30df0.9400d","name":"Date/Time mail","func":"var D1 = {payload: msg.header.date};\nreturn [D1];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":200,"wires":[["91fb4a14.626178"]]},{"id":"5f482705.4e5658","type":"inject","z":"baa30df0.9400d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":260,"wires":[["c7490f42.73715"]]},{"id":"c7490f42.73715","type":"function","z":"baa30df0.9400d","name":"Date/Time now","func":"var d = new Date();\n//var n = d.getTime();\nmsg.payload = d;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":260,"wires":[["daa9ff18.5c786"]]},{"id":"91fb4a14.626178","type":"debug","z":"baa30df0.9400d","name":"Date/Time mail","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":200,"wires":[]},{"id":"daa9ff18.5c786","type":"debug","z":"baa30df0.9400d","name":"Date/Time now","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":260,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/006a6e821192bc701cd1a980134e2bd43f272685.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [15 April 2021 06:49 UTC](https://discourse.nodered.org/t/solved-data-compare-email-date-now/44211/2 "2021-04-15T06:49:02Z")

</div>

The problem is you are over thinking this.

As you already have a function node where you extract the email date, you simply need to do the work there.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f5add0aa98c989384e31005042d95a8352899ea3.png)

```auto
var D1 = msg.header.date.valueOf(); //email epoch
var now = Date.now(); //now epoch
var diff = Math.abs(D1 - now) / 1000; //get difference in seconds
msg.payload = (diff > 20); //true if >20s otherwise false.
return msg;

```

NOTE: if msg.header.date is a string, this will not work. you would need to wrap it with `new Date(msg.header.date)`

---

<div class="post-metadata">

### Author: ![steinerma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinerma/32/37666_2.png) [@steinerma](https://discourse.nodered.org/u/steinerma)
#### Post date: [15 April 2021 08:18 UTC](https://discourse.nodered.org/t/solved-data-compare-email-date-now/44211/3 "2021-04-15T08:18:52Z")

</div>

Hi Steve-Mcl,  
thank you for your flow! Works great! Yes, sometimes i'm over thinking 😀

---

<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: [29 April 2021 08:19 UTC](https://discourse.nodered.org/t/solved-data-compare-email-date-now/44211/4 "2021-04-29T08:19:46Z")

</div>

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