Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

nifi - how to derive yesterday 's date like 09-12-2016 11:59:59 using now 09-13-2016 03:00:00 (i.e todays' date in nifi flows )

avatar

how to derive using todays date (now), yesterdays date with desired time stamp.

example

todays date is 09-13-2016 03:00:00 and derive yesterdays date 9-12-2016 11:59:59 always to in format of mm-dd-yyyy 11:59:00. always default timestamp to 11:59:00. we can do this in oracle using formatting the date but how can it be achieved in NIFI?

2 REPLIES 2

avatar
Super Mentor

@Sree Venkata

You can do this using a combination of NiFi Expression Language (EL) functions:

${now() :minus(${now():mod(86400000)}) :minus(43260000) :format('MM-dd-yyyy hh:mm:ss') }

This EL statement takes now subtracts the remainder resulting from dividing now by 86400000 (number of milliseconds in 24 hours) and then subtracts an additional 43260000 (12 hours and 1 minute) from that result and finally formatting the output in the date format you are looking for.

I confirmed this EL statement by using it in an UpdateAttribute processor:

7847-screen-shot-2016-09-21-at-125208-pm.png

and if I look at the attributes on a FlowFile that was processed by the above, I see:

7846-screen-shot-2016-09-21-at-123135-pm.png

You can see that the attribute "yesterday" is set to exactly one day earlier from "current time" and 11:59:00.

Thanks,

Matt

avatar
Super Mentor

There is the possibility that the time could differ slightly (ms) between when both now() functions are called in that expression language which could cause the result to push pack to 11:58:59. To avoid this you can simply reduce 43260000 by a few milliseconds (43259990) to ensure that does not happen so 11:59:00 is always returned.