I have an payload "payload.date" with format "2021-06-18"
How to write an function to check if the payload.date is today's date+1 day
If its true, forward message, if not, stop the message
Regards
Mons
I have an payload "payload.date" with format "2021-06-18"
How to write an function to check if the payload.date is today's date+1 day
If its true, forward message, if not, stop the message
Regards
Mons
Where is that coming from? If that comes from, for example, a Date object, then it may be simple.
Otherwise you could use new Date()
to give you a date object, add a day to it, then convert that to an ISO string with the appropriate time zone and compare the date part of the string with the string you have.
here is an example using JSONata expression an $moment(), it would be better if you feed a time in to
[{"id":"e4f5e458.7a6d1","type":"inject","z":"e169487f.02ad68","name":"201-96-08","props":[{"p":"payload.date","v":"2021-06-08","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":290,"y":140,"wires":[["322c5eec.745b0a"]]},{"id":"322c5eec.745b0a","type":"change","z":"e169487f.02ad68","name":"","rules":[{"t":"set","p":"datecheck","pt":"msg","to":"$moment(payload.date).subtract(1,\"days\").isAfter( $moment())","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":160,"wires":[["fe9ecc06.cc0f28"]]},{"id":"fe9ecc06.cc0f28","type":"switch","z":"e169487f.02ad68","name":"","property":"datecheck","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":200,"wires":[["f2878f0a.4a8d88"]]},{"id":"fec467b9.cddcb8","type":"inject","z":"e169487f.02ad68","name":"201-96-09","props":[{"p":"payload.date","v":"2021-06-09","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":290,"y":180,"wires":[["322c5eec.745b0a"]]},{"id":"f2878f0a.4a8d88","type":"debug","z":"e169487f.02ad68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":180,"wires":[]}]
Thanks for the help
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.