Support Questions
Find answers, ask questions, and share your expertise

How to convert string to date in NiFi

Solved Go to solution

How to convert string to date in NiFi

Explorer

Is there a simple way to convert a date string such as "Mar 16 2018 19:18:15 GMT" into date in NiFi?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to convert string to date in NiFi

Super Guru
@Alex M

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

72840-generateflowfile.png

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")} 

72841-updateattr.png

Output Flowfile attributes:-

72842-output.png

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.

View solution in original post

2 REPLIES 2

Re: How to convert string to date in NiFi

Super Guru
@Alex M

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

72840-generateflowfile.png

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")} 

72841-updateattr.png

Output Flowfile attributes:-

72842-output.png

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.

View solution in original post

Re: How to convert string to date in NiFi

New Contributor

@Shu - Thanks for your detailed answer. That helps.

What if I have a timestamp and I need to convert it to a string?