Apache Nifi: substract hours from column value with datetime format
Hello!
Input flowFile has column "date_time" with timestamp-millis type
The task is to update each value of column, by substracting 3 hours from datetime value. In fact I need to transform datetime value from timezone GMT +3 to timezone GMT +0
For example, value "2024-11-24 19:43:17" to be transformed in "2024-11-24 16:43:17"
I tried to use UpdateRecord with following script:
format(toNumber((/date_time):minus(3600)), "yyyy-MM-dd HH:mm:ss")
And, as expected, transformation failed with exception: "Unrecognized token 'minus'..."
Operation "minus" applied to attributes values. And "date_time" is not an attribute.
As an alternative, I considered next way:
1. SplitText for splitting one FlowFile into N FlowFiles, where N - is the number of records.
2.UpdateAttribute to add new attribute "dateTime" for each of N flowFiles by:
dateTime <- /date_time
3. UpdateRecord for each of N flowFiles with script: /date_time <- ${dateTime:toNumber:minus(3600):format("yyyy-MM-dd HH:mm:ss")}
4.Merge N flowFiles to one FlowFile
But this way seem to be too complicated. Is there are more straightforward way? ))




