Search code examples
apache-nifinifi-processor

Get the previous month in NIFI


I am using the update attribute to check my file if its for previous month.

My file name looks like this 2_EXAMPLE_MMM_2023.

I am using the expression

${now():minusMonths(1):format('dd_EXAMPLE_MMM_YYYY')}

But my version says there is a unexpected token. I would like to use the UpdateAttribute processor to set for just the previous month. Can I get the correct expression to use it?

TIA


Solution

  • ${now():format("yyyy-MM-01"):toDate("yyyy-MM-dd"):minus(1000):format("yyyy-MM-01")}
    //^now  ^1st day of month    ^to date             ^minus 1sec ^1st of prev month