Pentaho

 View Only

 Pentaho kettle convert date to unix

  • Pentaho
  • Kettle
  • Pentaho
  • Pentaho Data Integration PDI
Manuel munoz's profile image
Manuel munoz posted 05-16-2019 05:46

I'm trying to pacha a string format dated "2019-05-14 13:30:00" to a UNIX format.

In javascript I got it but in the javascript kettle module I am not able to return the numeric value 1557833442

the line of code is this:

const tests = (new Date ("2019-05-14 13:30:00"). getTime () / 1000);
#Kettle
#PentahoDataIntegrationPDI
#Pentaho
Virgilio Pierini's profile image
Virgilio Pierini

Hi,

as far as I know there are many options (just google and you'll find many forum messages) varying from

- using  java.text.SimpleDateFormat("yyyyMMdd")

to

- using a select step for changing metadata datatype with a specific format

Given your example you should be aware that the JS step uses Rhino (somebody please correct me if I'm wrong) which might have a different behaviour from JS6. For example I remember the Date constructor is locale dependent and -in short- not recommended.

I hope you can find a solution in the two examples proposed, but, if you are in a more complex scenario you can even import a js library like Moment.js for special calculations. This once happened to me

My regards

Virgilio