Nifi - how to add days to the date
Asked Answered
S

1

6

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.

Sarracenia answered 6/8, 2018 at 16:38 Comment(0)
T
15

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")}

enter image description here enter image description here

Troposphere answered 6/8, 2018 at 17:0 Comment(2)
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.