Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Nifi UpdateAttribute Date formatation

Solved Go to solution

Nifi UpdateAttribute Date formatation

Hi,

how can I get from a String like this "20170115" a date format, that I can put in a cassandra collumn with date format?

I tried in updateAttribute processor this ${column.2:toDate("yyyy/MM/dd", "GMT")} but it didnt worked.

column.2 is a csv column with values like "20170115".

thx for help

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Nifi UpdateAttribute Date formatation

Super Guru

@Andy Gisbo

if your column.2 attribute having value as "20170115" //with double quotes surrounded.

you need to remove double quotes before todate function, try the below Expression in your update attribute processor.

${column.2:replaceAll('"',''):toDate("yyyyMMdd","GMT")} //first replace double quotes with empty value and then parse column.2 value to date and convert that to GMT.

In addition if you want to format "20170115" to "2017-01-15" then

${column.2:replaceAll('"',''):toDate("yyyyMMdd","GMT"):format("yyyy-MM-dd"):append('"'):prepend('"')} //converting column.2 to gmt format then append and prepend the value with "(double quotes)

In addition if you want to format "20170115" to 2017-01-15 then

${column.2:replaceAll('"',''):toDate("yyyyMMdd"):format("yyyy-MM-dd")}

2.if your column.2 attribute having value as 20170115 //without double quotes

Change the expression in update attribute processor as below

${column.2:toDate("yyyyMMdd", "GMT")} 

This expression will return GMT value.

In addition if you want to format 20170115 to 2017-01-15 then

${column.2:toDate("yyyyMMdd","GMT"):format("yyyy-MM-dd")}

what if still doesn't work?

Goto Right top corner on you NiFi UI and click on GlobalMenu(i.e you can see three horizontal lines at top right corner)

Click on Help then click on Expression Language Guide and look for toDate function is it supports converting to GMT format or not. Because these conversion to GMT format is not supported in NiFi 1.1.0 version.

View solution in original post

2 REPLIES 2
Highlighted

Re: Nifi UpdateAttribute Date formatation

Super Guru

@Andy Gisbo

if your column.2 attribute having value as "20170115" //with double quotes surrounded.

you need to remove double quotes before todate function, try the below Expression in your update attribute processor.

${column.2:replaceAll('"',''):toDate("yyyyMMdd","GMT")} //first replace double quotes with empty value and then parse column.2 value to date and convert that to GMT.

In addition if you want to format "20170115" to "2017-01-15" then

${column.2:replaceAll('"',''):toDate("yyyyMMdd","GMT"):format("yyyy-MM-dd"):append('"'):prepend('"')} //converting column.2 to gmt format then append and prepend the value with "(double quotes)

In addition if you want to format "20170115" to 2017-01-15 then

${column.2:replaceAll('"',''):toDate("yyyyMMdd"):format("yyyy-MM-dd")}

2.if your column.2 attribute having value as 20170115 //without double quotes

Change the expression in update attribute processor as below

${column.2:toDate("yyyyMMdd", "GMT")} 

This expression will return GMT value.

In addition if you want to format 20170115 to 2017-01-15 then

${column.2:toDate("yyyyMMdd","GMT"):format("yyyy-MM-dd")}

what if still doesn't work?

Goto Right top corner on you NiFi UI and click on GlobalMenu(i.e you can see three horizontal lines at top right corner)

Click on Help then click on Expression Language Guide and look for toDate function is it supports converting to GMT format or not. Because these conversion to GMT format is not supported in NiFi 1.1.0 version.

View solution in original post

Highlighted

Re: Nifi UpdateAttribute Date formatation

thx for the answer, it worked perfectly.

Don't have an account?
Coming from Hortonworks? Activate your account here