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.

John
  • 187
  • 1
  • 3
  • 12

1 Answers1

14

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

notNull
  • 30,258
  • 4
  • 35
  • 50
  • 1
    Thanks Shu. Exactly what I was looking for. – John Aug 07 '18 at 15:31
  • @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) – maximegir Jul 08 '20 at 19:59