Could somebody tell me how I can add x number of days to a date attribute that is in the format ("yyyy-MM-dd") in Nifi.
Nifi - how to add days to the date
Asked Answered
Use toDate function to convert into unixtime then use plus function with milliseconds and finally use format function to get your desired format
Adding 1 day:
${date:toDate("yyyy-MM-dd"):toNumber():plus(86400000):format("yyyy-MM-dd")}
Example:
i'm having date attribute to the flowfile with value as 2018-01-10 and want's to add 1 day to the date attribute value.
Milliseconds for 1 day(24hr) is 86400000 so in the below expression i'm adding one day to the date attribute value.
Add new attribute in update attribute processor as
add_day and value as
${date:toDate("yyyy-MM-dd"):toNumber():plus(86400000):format("yyyy-MM-dd")}
Thanks Shu. Exactly what I was looking for. –
Sarracenia
@Shu What if I have a more elaborate date (with time) is there a way to do that using expression language (to add n number of days to an existing date and keep the time intact) –
Nymphalid
© 2022 - 2024 — McMap. All rights reserved.