Support Questions

Find answers, ask questions, and share your expertise

Convert date time to 24 hour format in NiFi

avatar
Explorer

I am trying to convert the following date format -> 8/6/2023 12:46 am to this format -> 2023-08-06 00:46:00.

I want to do this using NiFi. I have tried using the UpdateRecod processor for the same and used toDate() and format() for the above conversion. But it didn't give the desired results.

How can I achieve this using NiFi?

1 REPLY 1

avatar

@janvit04 The pattern you need is this:

 

${input_date:toDate("MM/dd/yyyy hh:mm:ss"):format("yyyy-MM-dd HH:mm:ss")}

I did this in a test which you can find here.  In this example I have UpdateAttribute with an input attribute called input_date and its string value is  "8/6/2023 12:46 am".   In next UpdateAttribute i do the toDate and format.    With this setup you may need to modify the format in toDate function to match your input string until it gets right format.  For example I thought it should be m/d/yyyy but i got right output using MM/dd/yyyy.