Issue with date calculation

Hello,

I would like to find the day-2 date. Here is the value I used. It worked before but does not work for the last few days/week (I didn’t change anything). As you can see, the object is good but the data displayed correspond to today’s date.

Is it a bug?

Thanks,
Julien

@julien1 I’m getting the same result, and although I do not have a solution for you, this may be a work-around:

today = new Date()
days = 86400000 //number of milliseconds in a day
twoDaysAgo = new Date(today - (2*days))

return {twoDaysAgo: twoDaysAgo};
1 Like

Hi @julien1, I suppose this is the Date & Time node expecting a string, but your expression {{ $now.minus({days: 2}) }} would return a JS object instead. In addition to what @dickhoning has shared you could try either one of the below options:

  1. Use an expression such as {{ $now.minus({days: 2}).toISO() }} to return a string instead of an object. The Date & Time node would then handle this correctly:
  2. Seeing you already use Luxon in your expression, don’t use the Date & Time node at all and simply handle the formatting in your expression as well. This should work in any node, for example {{ $now.minus({days: 2}).toFormat('yyyyMMdd') }}:
    image
    All available tokens you can use in the .toFormat() method are listed here.

It worked, thanks a lot guys :slight_smile:

1 Like

Glad to hear, thanks so much for confirming!

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