Created 05-15-2018 11:10 AM
Is there a simple way to convert a date string such as "Mar 16 2018 19:18:15 GMT" into date in NiFi?
Created on 05-15-2018 11:54 AM - edited 08-18-2019 12:28 AM
Use the below expression language to convert into date
${<attribute-name>:toDate("MMM dd yyyy hh:mm:ss","GMT"):format("yyyy-MM-dd HH:mm:ss")}
in the above expression language we are matching the input date by using toDate function and using format function we are formatting the date value to yyyy-MM-dd HH:mm:ss.
to get only the date then use format function until date i.e yyyy-MM-dd
${<attribute-name>:toDate("MMM dd yyyy hh:mm:ss","GMT"):format("yyyy-MM-dd")}
Example:-
I'm having generateflowfile processor with new property dr added as
UpdateAttribute Configs:-
Added two properties in update attribute processor as below
gmt
${dr:toDate("MMM dd yyyy hh:mm:ss","GMT"):format("yyyy-MM-dd HH:mm:ss")}
not_gmt
${dr:toDate("MMM dd yyyy hh:mm:ss"):format("yyyy-MM-dd HH:mm:ss")}
Output Flowfile attributes:-
In addition we can use timezone with format function also,For more details regarding date conversions refer to this link.
-
If the Answer addressed your question, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
Created on 05-15-2018 11:54 AM - edited 08-18-2019 12:28 AM
Use the below expression language to convert into date
${<attribute-name>:toDate("MMM dd yyyy hh:mm:ss","GMT"):format("yyyy-MM-dd HH:mm:ss")}
in the above expression language we are matching the input date by using toDate function and using format function we are formatting the date value to yyyy-MM-dd HH:mm:ss.
to get only the date then use format function until date i.e yyyy-MM-dd
${<attribute-name>:toDate("MMM dd yyyy hh:mm:ss","GMT"):format("yyyy-MM-dd")}
Example:-
I'm having generateflowfile processor with new property dr added as
UpdateAttribute Configs:-
Added two properties in update attribute processor as below
gmt
${dr:toDate("MMM dd yyyy hh:mm:ss","GMT"):format("yyyy-MM-dd HH:mm:ss")}
not_gmt
${dr:toDate("MMM dd yyyy hh:mm:ss"):format("yyyy-MM-dd HH:mm:ss")}
Output Flowfile attributes:-
In addition we can use timezone with format function also,For more details regarding date conversions refer to this link.
-
If the Answer addressed your question, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
Created 06-18-2019 12:55 PM
@Shu - Thanks for your detailed answer. That helps.
What if I have a timestamp and I need to convert it to a string?