Help with incrementing month

I have a script that updates a date helper and it doesn't seem to be working correctly anymore. I have it set to increment the month, but for some reason it's incrementing the same numbers in the year as well.

{{ now().strftime('%Y-%m-%d') | replace(now().month, now().month + 1) }}

results in 3033-03-17

Any ideas what's going on with it? Potentially just a bug?

Posted Feb 18, 2023, 4:10 AM UTC

06
ProfessorSlocombe•

Hi,

​

Try {{ [now().year,now().month+1,now().day] |join('-')}}

Which will add 1 month to the year but it does return a string.

4
CodenameJOP•

That works perfect. Thanks.

1
ProfessorSlocombe•

To answer your actual question.

The current month is Feb with a numeric value of 2, next month is March with a numeric value of 3

The current year is 2022

Your replace is replacing all 2's in the string with 3s.

5
CodenameJOP•

Right, but why is that incrementing all the 2s? Shouldn't the now().month + 1 just increment the month?

2
mekaneck84•

The code, now().month resolves as a number, e.g. “2” when it is February.

So your code replace(now().month, now().month+1) means “replace 2 with 2+1”. Which means “replace any instance of 2 with 3”.

6
[deleted]•

[deleted]

1