Substract 5 minutes of a date&time result in the Function node

Hello,

I am new in n8n (and javascript too)!

My question is:

In my process, the Cron node checks a web application every 5 minutes. Afterwards, the Function node gets the today’s date from Cron with the following code:

const utcTimeStamp = new Date();
items[0].json.today = utcTimeStamp;

return items;

Example of a result:
[
{
“today”: “2021-05-13T09:19:22.237Z”
}
]

Since I prefer another format, the Date&Time node will then get the result mentioned above, “2021-05-13T09:19:22.237Z” and convert it to “13.05.2021 09:19:22” format.

However, I would like to substract 5 minutes from “13.05.2021 09:19:22”.

Is it possible to substract these 5 minutes in the Function node already? How?

Thanks in advance for your support,

sincerely

Lara

@lcda1
You can do this in the function node:

const utcTimeStamp = new Date();
items[0].json.today = utcTimeStamp;
items[0].json.subtracted = new Date(utcTimeStamp - (5*60*1000));

return items;
5 Likes

Hi @shrey-42

Thank you very much for your reply!
I then found myself a solution but I like yours better!

kind regards

Lara

Hey @lcda1!

We also have added the functionality to add and subtract time in the Date and Time node. If you update to the latest version, you will be able to use the operation :slight_smile:

6 Likes

Hi @harshil1712,

I am planning to update these days! Thank you very much for the information!

Sincerely,

Lara

2 Likes