Support Questions

Find answers, ask questions, and share your expertise

NiFi Convert String to Date Attribute

New Contributor

I'm new to NiFi and having an issue with a workflow. I created a MySQL query to pull in training course completions into a JSON RecordSetWriter format. When I view the queue contents, the "completed_on" attribute shows as a string {"name":"completed_on","type":["null","string"]} whereas it needs to be "datetime". The data appears as a string formatted like this. ("completed_on":"1605870000000")

How can I convert the attribute back to a date format so I can get the data to read in YYYY-MM-DD format?


Expert Contributor


You can do this with UpdateAttribute.

In my example:
Date_Time ==> ${YourUnixTimestamp:toDate():format('YYYY-MM-dd hh:mm:ss.SSS', 'UTC')}

YourDate_YYYY-MM-dd ==>  ${YourUnixTimestamp:toDate():format('YYYY-MM-dd')}


You can check the result here:
But you have to remove the last three digits of the value.

Hope this helps!