Skip to main content
MWM
Silver ⭐️⭐️⭐️
December 18, 2023
Question

Problem with transform date to long in nifi

Hi guys,

I have some problems with transform date from string to long in NIFI. I have date like this: "02-01-1968|" and I need to transform this to long. i am using UpdateAttribte Processor to format it to number like this: ${my_date:toDate("dd-MM-yyyy","GMT"):toNumber()})} but I have result like this: "my_date" : -63072000000 .Does anyone know how to solve this better? 

3 replies

SAMSAL
Platinum ⭐️⭐️⭐️
December 18, 2023

Hi @MWM ,

The reason you are getting negative value is because the minimum date in epoch is "January 1st, 1970"  which corresponds to "0".  It turns out you can still convert the negative value back to date using the following expression:

${my_date:toDate():format("dd-MM-yyyy")}

If that helps please accept solution.

Thanks

 

Translate
MWM
MWMAuthor
Silver ⭐️⭐️⭐️
December 18, 2023

Hi @SAMSAL , Yes i can convert negative value back but i need to send this date as long to other system and this is my problem with converting this date to long in nifi using toNumber() because my value is negative 

Translate
SAMSAL
Platinum ⭐️⭐️⭐️
December 18, 2023

Is the problem that the other system doesnt take negative values?

Translate