'NiFi How to Add Months to a Date

I know one can add milliseconds to a date for adding days or weeks:

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#now

But since months' lengths are different, that will not work. How can I add 6 months to the now() function of NiFi?



Solution 1:[1]

this code subtract 60 days from a attribute named 'date_original' and add new attribute with the new date

flowFile = session.get()
if(!flowFile) return
     formatoAccettato = "yyyy-MM-dd"    
     dataOriginale = flowFile.getAttribute('data_originale')
     dataOriginaleDate = Date.parse(formatoAccettato, dataOriginale)
     sottrazione = dataOriginaleDate - 60
     dataSottratta = sottrazione.format(formatoAccettato)
     flowFile = session.putAttribute(flowFile, 'data_modificata', dataSottratta)
session.transfer(flowFile, REL_SUCCESS)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1