# Function for yesterday?

**URL:** <https://discourse.nodered.org/t/function-for-yesterday/60654>\
**Category:** General\
**Created:** [1 April 2022 18:02 UTC](https://discourse.nodered.org/t/function-for-yesterday/60654 "2022-04-01T18:02:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasazick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jasazick/32/38635_2.png) [@jasazick](https://discourse.nodered.org/u/jasazick)\
**Post date:** [1 April 2022 18:02 UTC](https://discourse.nodered.org/t/function-for-yesterday/60654/1 "2022-04-01T18:02:21Z")

</div>

I have an global variable that stores as the following date/timestamp example:  
April 1, 2022 12:57 PM

I'm pretty sure this maps to LLL in the Date/Time Formatter Node

What I'd like to do is be able to have a function node that would change based on that global variable being yesterday or not.

So pseduocode

```auto
if global.get('mailbox') = yesterday 
{ do X }
else 
{ do Y }

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [1 April 2022 19:58 UTC](https://discourse.nodered.org/t/function-for-yesterday/60654/2 "2022-04-01T19:58:28Z")

</div>

```javascript
const date = new Date()
const yesterday = date.setDate(date.getDate() - 1)

```

Though that might not do exactly what you expect since that calculation returns a timestamp 24 hours ago (give or take issues with DST). Depends whether you want to compare against any time yesterday or simply any time over 24 hours ago.

If you need to set `yesterday` to "00:00" in order to compare against any time yesterday, you could change to something like:

```javascript
const date = new Date()
const yesterday = date.setDate(date.getDate() - 1)
yesterday.setTime(00,00)

```

---

<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:** [31 May 2022 19:59 UTC](https://discourse.nodered.org/t/function-for-yesterday/60654/3 "2022-05-31T19:59:01Z")

</div>

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