Subtract one month form a date as string (received via webhook)

Hi all, I receive the following date 07/12/2021 as string via webhook in a var called {{ $json["Sent"] }}.

I’m using this inside a set node and would like to subtract a month from 07/12/2021 in order to be able to assign then 11/2021 to a specific var (I can discard the day, just need month and year).

Should be something like {{ new Date($json["Sent"]).getMonth() -1 }} but this returns 5:

Any suggestions how to do this? Thanks for any hint;)

i use this for getting the last 7 days from now

{{ new Date(new Date().getTime()-(7*24*60*60*1000)).toISOString()}}
1 Like

Hi @eim, did you have a look at the Date & Time node?

This can perform calculations on the date string you have described and also format it as you have described (as it supports custom formats):


Example Workflow
1 Like

Works great:


Thanks for the support;)

Your calculation is correct, it returns the month in the format (0 to 11)
5 is month 6