Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Nifi UpdateAttribute Date formatation

avatar
Contributor

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

avatar
Master 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

avatar
Master 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.

avatar
Contributor

thx for the answer, it worked perfectly.