Support Questions

Find answers, ask questions, and share your expertise

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 )

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


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?


Master Guru

@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:


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


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



Master Guru

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.